将值传递给Javascript函数
我正在调用jQuery函数,但警报函数显示[object]。检查值有效,但传递的id值无效 下面是从html输出获取的函数调用:将值传递给Javascript函数,javascript,jquery,Javascript,Jquery,我正在调用jQuery函数,但警报函数显示[object]。检查值有效,但传递的id值无效 下面是从html输出获取的函数调用: <td class="myGroups"> <input class="chkSubscribed" type="checkbox" onclick="UpdateSubscription(2)" name="subscribed"> </td> 谢谢你的帮助 这里有几个不同的问题 使用alert()进行调试。这几乎总是比
<td class="myGroups">
<input class="chkSubscribed" type="checkbox" onclick="UpdateSubscription(2)" name="subscribed">
</td>
谢谢你的帮助 这里有几个不同的问题
alert()
进行调试。这几乎总是比使用console.log()
更糟糕。传递给alert
的所有内容都转换为字符串,这就是为什么您看到的是“[object object]”
,而不是有用的内容。切换到console.log()
,您将看到一些有意义的内容id
设置的对象onclick
处理程序与jQuery绑定的change
处理程序没有任何关系这里有几个不同的问题
alert()
进行调试。这几乎总是比使用console.log()
更糟糕。传递给alert
的所有内容都转换为字符串,这就是为什么您看到的是“[object object]”
,而不是有用的内容。切换到console.log()
,您将看到一些有意义的内容id
设置的对象onclick
处理程序与jQuery绑定的change
处理程序没有任何关系function moo(id) {
//code here
}
<input id="2" class="chkSubscribed" type="checkbox" name="subscribed">
$(".chkSubscribed").change(function() {
id=this.id;
//and the rest of the code as you wrote
});
如果要使用更改事件执行此操作,可以按如下方式为输入提供所需编号的id:
function moo(id) {
//code here
}
<input id="2" class="chkSubscribed" type="checkbox" name="subscribed">
$(".chkSubscribed").change(function() {
id=this.id;
//and the rest of the code as you wrote
});
你做错了
您需要调用函数或使用更改事件
如果要调用函数,请按如下方式创建函数:
function moo(id) {
//code here
}
<input id="2" class="chkSubscribed" type="checkbox" name="subscribed">
$(".chkSubscribed").change(function() {
id=this.id;
//and the rest of the code as you wrote
});
如果要使用更改事件执行此操作,可以按如下方式为输入提供所需编号的id:
function moo(id) {
//code here
}
<input id="2" class="chkSubscribed" type="checkbox" name="subscribed">
$(".chkSubscribed").change(function() {
id=this.id;
//and the rest of the code as you wrote
});