Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将值传递给Javascript函数_Javascript_Jquery - Fatal编程技术网

将值传递给Javascript函数

将值传递给Javascript函数,javascript,jquery,Javascript,Jquery,我正在调用jQuery函数,但警报函数显示[object]。检查值有效,但传递的id值无效 下面是从html输出获取的函数调用: <td class="myGroups"> <input class="chkSubscribed" type="checkbox" onclick="UpdateSubscription(2)" name="subscribed"> </td> 谢谢你的帮助 这里有几个不同的问题 使用alert()进行调试。这几乎总是比

我正在调用jQuery函数,但警报函数显示[object]。检查值有效,但传递的id值无效

下面是从html输出获取的函数调用:

<td class="myGroups">
    <input class="chkSubscribed" type="checkbox" onclick="UpdateSubscription(2)" name="subscribed">
</td>

谢谢你的帮助

这里有几个不同的问题

  • 使用
    alert()
    进行调试。这几乎总是比使用
    console.log()
    更糟糕。传递给
    alert
    的所有内容都转换为字符串,这就是为什么您看到的是
    “[object object]”
    ,而不是有用的内容。切换到
    console.log()
    ,您将看到一些有意义的内容
  • jQuery事件回调传递一个。该对象就是
    id
    设置的对象
  • 内联
    onclick
    处理程序与jQuery绑定的
    change
    处理程序没有任何关系

  • 这里有几个不同的问题

  • 使用
    alert()
    进行调试。这几乎总是比使用
    console.log()
    更糟糕。传递给
    alert
    的所有内容都转换为字符串,这就是为什么您看到的是
    “[object object]”
    ,而不是有用的内容。切换到
    console.log()
    ,您将看到一些有意义的内容
  • jQuery事件回调传递一个。该对象就是
    id
    设置的对象
  • 内联
    onclick
    处理程序与jQuery绑定的
    change
    处理程序没有任何关系
  • jQuery函数将传递事件对象,而不是更改对象的id—您将其视为当前id。

    jQuery函数将传递事件对象,而不是更改对象的id—您将其视为当前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
    });
    
    如果要使用更改事件执行此操作,可以按如下方式为输入提供所需编号的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
    });