我试图在链接点击时调用一个jquery函数,但没有成功:
这是我的HTML:
<a href="..." id="removeItem" checkID="12" >Delete</a>
<a href="..." id="removeItem" checkID="13" >Delete</a>
<a href="..." id="removeItem" checkID="14" >Delete</a>
$("#removeItem").click(function(checkID) {
return false;
var checkID = $(this).attr("checkID");
$("#removeDialog").dialog( {
buttons: {
"No" : function () {
$(this).dialog("destroy");
$('input#CheckName').focus();
},
"Yes": function () {
$.ajax({
url: "itemRemoveWS.html?id=checkID",
data: {
"action" : "remove",
"id" : checkID
},
success: function (data) {
$("#removeDialog").dialog("destroy");
var ang = '';
var obj = $.parseJSON(data);
$.each(obj, function() {
ang += '<table class="form"><tr><td width="45">' + this["CheckID"] + '</td><td width="140">' + this["Name"] + '</td><td width="95">' + this["CheckNumber"] + '</td><td align="right" width="70">$' + this["Amount"] + '</td><td width="220" style="padding-left: 15px;">' + this["Description"] +'</td><td><a href="#">Delete</a></td></tr></table>';
});
$('#container').html(ang);
$("input#Amount").val('');
$("input#CheckName").val('');
$("input#Check_Number").val('');
$("select#Company").val('MMS');
$("th#dept").hide();
$('input#CheckName').focus();
}
});
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
您return false;在点击事件回调函数中有第一条指令.这意味着你什么都不做.
将它放在逻辑的最后一行或更好地将其更改为e.preventDefault(); 使用
$("#removeItem").click(function(e) {...}
Run Code Online (Sandbox Code Playgroud)
作为旁注,$("#removeItem").click(function(checkID) {} checkID将是这里引用的引用事件,而不是元素id属性.
同样,ID属性必须对每个html页面上的每个元素都是唯一的.
| 归档时间: |
|
| 查看次数: |
34650 次 |
| 最近记录: |