Jquery版本1.11.0問題:點(diǎn)擊修改鏈接,在彈出的對話框中,點(diǎn)提交按鈕,click事件會執(zhí)行多次。而用原生js則沒有問題。并且提交后,第二次提交后,多個數(shù)據(jù)都變成一個了。代碼如下:點(diǎn)擊了多少次修改,點(diǎn)提交時就會alert出多少個222222http://jsfiddle.net/D7eEd/出問題部分用原生js實(shí)現(xiàn):http://jsfiddle.net/vowmmm/n5yzy/個人認(rèn)為原因是:click事件里不能包含click事件?不知道是不是這樣。為方便查看,附帶整個文檔Document*{margin:0;padding:0;}#table{border:1pxsolidgray;border-collapse:collapse;width:500px;}tr{height:30px;}th{border:1pxsolidgray;}td{border:1pxsolidgray;text-align:center;}tda{margin-right:5px;color:blue;text-decoration:none;}#popDiv,#editDiv{border:1pxsolidsilver;width:315px;padding:1px;margin-top:10px;position:absolute;left:38%;z-index:4;display:none;}.popp{height:30px;margin-top:20px;clear:both;}.popa{display:block;float:right;text-decoration:none;font-size:12px;}.pop.input{height:20px;line-height:20px;}/*#bottom{width:100%;height:30px;margin:0auto;}*/#sub{display:block;height:30px;margin:0auto;}.mask{background-color:#000;position:absolute;left:0;top:0;z-index:2;}姓名年齡職位工資操作張三23PHP79999修改李四21Java12000修改王五34Python29999修改趙六37Javascript65450修改close姓名:年齡:職位:工資://點(diǎn)擊'修改'鏈接$('a.edit').click(function(){vararr=[];$(this).parent().siblings().each(function(){arr.push($(this).text());});$('#editDiv').show().find('p').each(function(i){$(this).find('input:text').val(arr[i]);});varaTr=$(this);$('#sub').click(function(){alert('2222222');vardata=[];$(this).prevUntil('a.close').each(function(){data.push($(this).find('input:text').val());});data.reverse();aTr.parent().siblings().each(function(i){$(this).text(data[i]);});$(this).parent().hide();$('div.mask').remove();});//原生JS實(shí)現(xiàn)點(diǎn)擊,沒有問題/*document.getElementById('sub').onclick=function(){alert('1111111');vardata=[];$(this).prevUntil('a.close').each(function(){data.push($(this).find('input:text').val());});data.reverse();aTr.parent().siblings().each(function(i){$(this).text(data[i]);});$(this).parent().hide();$('div.mask').remove();};*///添加遮罩層varmaskHeight=$(document).height();varmaskWidth=$(document).width();$('').appendTo($('body'));$('div.mask').css({'width':maskWidth,'height':maskHeight,'opacity':0.4});});$('a.close').click(function(){$(this).parent().hide();$('div.mask').remove();});
Jquery中click事件重復(fù)執(zhí)行的問題
慕妹3242003
2019-04-09 20:25:34