我正在使用ajax加载页面数据。我想在点击输入时运行一个函数,其类型是图像,其 id 以“SubmitVote”开头,后跟一些整数。下面是代码,它不起作用。
$(function() {
$('input:image[id^="submitVote"').live('click',function(){
if(this.id.match(/^submitVote(\d+)$/)){
var vote=$("#rtngCmb").val();
var text=$("#userNote").val();
var alertId=RegExp.$1;
postVote(alertId, vote, text);
}
});
});
如何做到这一点?
最佳答案
如果您无法修改标记以包含类,请尝试以下操作:
$('input[type="image"][id^="submitVote"]').live('click', function() {
if (this.id.match(/^submitVote(\d+)$/)) {
var vote = $("#rtngCmb").val();
var text = $("#userNote").val();
var alertId = RegExp.$1;
postVote(alertId, vote, text);
}
});
此外,您的选择器中缺少最后一个 ]
不起作用的原因。
关于jquery - 使用 jquery 对输入类型图像使用点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5614055/