ajax点击事件click触发两次,Jquery中click事件重复执行的问题

Jquery版本1.11.0

问题:点击修改链接,在弹出的对话框中,点提交按钮,click事件会执行多次。而用原生js则没有问题。

并且提交后,第二次提交后,多个数据都变成一个了。

代码如下:

点击了多少次修改,点提交时就会alert出多少个222222

http://jsfiddle.net/D7eEd/

个人认为原因是:

click事件里不能包含click事件?不知道是不是这样。

为方便查看,附带整个文档

Document

* {margin: 0; padding: 0;}

#table {border: 1px solid gray; border-collapse: collapse; width: 500px;}

tr {height: 30px;}

th {border: 1px solid gray;}

td {border: 1px solid gray;text-align: center;}

td a {margin-right: 5px; color: blue; text-decoration: none;}

#popDiv, #editDiv {border: 1px solid silver; width: 315px; padding: 1px; margin-top: 10px; position: absolute; left: 38%; z-index: 4; display: none;}

.pop p {height: 30px; margin-top: 20px; clear: both;}

.pop a {display: block; float: right; text-decoration: none; font-size: 12px;}

.pop .input {height: 20px; line-height: 20px;}

/*#bottom {width: 100%; height: 30px; margin: 0 auto;}*/

#sub {display: block; height: 30px; margin: 0 auto;}

.mask {background-color: #000; position: absolute; left: 0; top: 0; z-index: 2;}

姓名年龄职位工资操作
张三23PHP79999修改
李四21Java12000修改
王五34Python29999修改
赵六37Javascript65450修改

close

姓名:

年龄:

职位:

工资:

// 点击'修改'链接

$('a.edit').click(function () {

var arr = [];

$(this).parent().siblings().each(function () {

arr.push($(this).text());

});

$('#editDiv').show().find('p').each(function (i) {

$(this).find('input:text').val(arr[i]);

});

var aTr = $(this);

$('#sub').click(function () {

alert('2222222');

var data = [];

$(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实现点击,没有问题

/*document.getElementById('sub').onclick = function () {

alert('1111111');

var data = [];

$(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();

};*/

// 添加遮罩层

var maskHeight = $(document).height();

var maskWidth = $(document).width();

$('

$('div.mask').css({

'width':maskWidth,

'height':maskHeight,

'opacity':0.4

});

});

$('a.close').click(function () {

$(this).parent().hide();

$('div.mask').remove();

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值