Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.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 在onchange事件中,能否传递不是当前控件的参数?_Javascript_Jquery - Fatal编程技术网

Javascript 在onchange事件中,能否传递不是当前控件的参数?

Javascript 在onchange事件中,能否传递不是当前控件的参数?,javascript,jquery,Javascript,Jquery,如果我有一个函数: function passSomeParams(p0, p1) { window.Location.href = "/something/anotherthing.aspx?firstParam=" + p0 + "&secondParam=" + p1; } 我可以传递除电流控制之外的输入吗?我想在下面做一些类似的事情,但无法让它工作,也无法在网上找到资源,无论是否可行 <asp:CheckBox runat="server" ID=

如果我有一个函数:

function passSomeParams(p0, p1) {
    window.Location.href = "/something/anotherthing.aspx?firstParam=" +
        p0 + "&secondParam=" + p1;
}
我可以传递除电流控制之外的输入吗?我想在下面做一些类似的事情,但无法让它工作,也无法在网上找到资源,无论是否可行

<asp:CheckBox runat="server" ID="chkCheckboxA" />
<asp:CheckBox runat="server" ID="chkCheckboxB"
    onchange="passSomeParams(this.value, chkCheckboxA.value)"/>

谢谢。非常感谢您的帮助。

如果必须像您那样使用内联事件处理程序来完成,那么您可以通过以下方式来完成。但是有更好的方法

function passSomeParams1(v1, v2) {    
    //Option 1
    var param1 = v1;
    var param2 = v2;
    // --;
}
function passSomeParams2(v1, v2) { 
    //Option 2
    var param1 = document.getElementById(v1).value;
    var param2 = document.getElementById(v2).value;
    // --;
}
没有内联事件处理程序:

jQuery:

$('#second').on("change", function() {
    //Option 4
    var param1 = $(this).val();
    var param2 = $("#first").val();
    // --;
});
HTML示例

<input type="checkbox" id="first" value="1" />
<input type="checkbox" id="second" value="2" onchange="passSomeParams1(this.value, document.getElementById('first').value)"/>

<input type="checkbox" id="first" value="1" />
<input type="checkbox" id="second" value="2" onchange="passSomeParams2(this.id, 'first')"/>

是的,你可以。你试过了吗?chkCheckboxA没有定义,因为它不是DOM对象。如果您确实需要这样做,document.getElementById'chkCheckboxA'.value
<input type="checkbox" id="first" value="1" />
<input type="checkbox" id="second" value="2" onchange="passSomeParams1(this.value, document.getElementById('first').value)"/>

<input type="checkbox" id="first" value="1" />
<input type="checkbox" id="second" value="2" onchange="passSomeParams2(this.id, 'first')"/>