javascript - table之間點(diǎn)擊循環(huán)傳遞值
問(wèn)題描述
現(xiàn)在有兩個(gè)table,table1 和table2 初始化狀態(tài)的時(shí)候,table中有數(shù)據(jù),點(diǎn)擊checkbox,數(shù)據(jù)傳遞到table2中,并且table1的數(shù)據(jù)刪除,這時(shí)候,如果點(diǎn)擊table2的checkbox,數(shù)據(jù)重新傳遞到table1中。
效果圖如下:
我能從table1中將數(shù)據(jù)傳遞到table2,代碼如下
$('#table1 input').click(function () {//var html=$(this).parent().parent();//$('#table2').append(html);});$('#table2 input').click(function(){var html=$(this).parent().parent();//$('#table1').append(html);});
主要使用這樣的方法,現(xiàn)在問(wèn)題在于,將tr整個(gè)對(duì)象傳遞過(guò)去之后,在點(diǎn)擊table2中的checkbox的時(shí)候,tr的對(duì)象傳遞不了,測(cè)試,顯示都沒有進(jìn)入點(diǎn)擊事件,這個(gè)是怎么回事??在線等,謝謝大家
問(wèn)題解答
回答1:var otable1=$(’#table1’),otable2=$(’#table2’);otable1.on(’click’,’input’,function(){//var otr= $(this).parent();//otable2.append(otr); otr.remove();})otable2.on(’click’,’input’,function(){//var otr= $(this).closest('li');//otable1.append(otr);//otr.remove();})
試下(保證#table1,#table1是一開始在頁(yè)面上的,不是未來(lái)元素),如果不行。代碼貼出來(lái),幫你測(cè)試下!
回答2:DEMO
<!DOCTYPE html><html><head>//<meta charset='utf-8'>//<meta name='viewport' content='width=device-width'><title>JS Bin</title>//<script src='https://code.jquery.com/jquery-3.1.0.js'></script> <style>table {border: 1px solid red;padding: 5px;}</style></head><body><table id='table1'><tr> <td><input type=’checkbox’ />123123</td></tr></table><table id='table2'><tr></tr> </table><script>$(document).on(’click’,’#table1 input’,function(){//var html = $(this).parent();$('#table2').append(html);})$(document).on(’click’,’#table2 input’,function(){var html = $(this).parent();//$('#table1').append(html);}) </script></body></html>
如果可行請(qǐng)采納哦,3Q。
相關(guān)文章:
1. android - 安卓做前端,PHP做后臺(tái)服務(wù)器 有什么需要注意的?2. mysql - ubuntu開啟3306端口失敗,有什么辦法可以解決?3. javascript - 從mysql獲取json數(shù)據(jù),前端怎么處理轉(zhuǎn)換解析json類型4. mysql - C#連接數(shù)據(jù)庫(kù)時(shí)一直這一句出問(wèn)題int i = cmd.ExecuteNonQuery();5. mysql replace 死鎖6. extra沒有加載出來(lái)7. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?8. thinkPHP5中獲取數(shù)據(jù)庫(kù)數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺(tái)消失不見。有圖有代碼,希望有人幫忙9. javascript - 微信網(wǎng)頁(yè)開發(fā)從菜單進(jìn)入頁(yè)面后,按返回鍵沒有關(guān)閉瀏覽器而是刷新當(dāng)前頁(yè)面,求解決?10. django - Python error: [Errno 99] Cannot assign requested address
