我试图在链接点击时调用一个
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(); } }); } } }); });
解决方法
你有假的回报;作为点击事件回调函数中的第一条指令.这意味着你什么都不做.
把它放在逻辑的最后一行,或者更好地将它改为e.preventDefault();运用
$("#removeItem").click(function(e) {...}
作为旁注,$(“#removeItem”).click(function(checkID){} checkID将是这里引用的引用事件,而不是元素id属性.
同样,ID属性必须对每个html页面上的每个元素都是唯一的.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。