Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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参数从asp.net传递到.focus_Javascript_Asp.net_Parameter Passing - Fatal编程技术网

如何将javascript参数从asp.net传递到.focus

如何将javascript参数从asp.net传递到.focus,javascript,asp.net,parameter-passing,Javascript,Asp.net,Parameter Passing,我在这里有点困惑。问题是,我有一个asp.net文本框,当maxlength为true且用户未点击某些键时,我想将其切换到下一个文本框。我的asp.net代码如下所示: <asp:TextBox ID="txbTransferBanknumber" Style="width: 50px;" MaxLength="4" Visible="true" runat="server" autocomplete="off" onkeyup="autoTabNextTextBox(this,'

我在这里有点困惑。问题是,我有一个asp.net文本框,当maxlength为true且用户未点击某些键时,我想将其切换到下一个文本框。我的asp.net代码如下所示:

<asp:TextBox ID="txbTransferBanknumber" Style="width: 50px;" MaxLength="4" 
Visible="true" runat="server" autocomplete="off"    onkeyup="autoTabNextTextBox(this,'txbTransferLedger')" CssClass="AutoTabFill" />
function autoTabNextTextBox(sender, nextTextBox) {

    var keyCode = (event.which) ? event.which : event.keyCode
    var mylength = $(sender).val().length;
    var maxlength = $(sender).attr('maxLength');

    if((keyCode != 37) && (keyCode != 39))
    {
        if ((keyCode != 8) && (keyCode != 16))
        {
            if (mylength == maxlength)
            {   
                $('.nextTextBox').focus();
                //nextTextBox.focus();                    
            }
        }
    }

}
如何将参数nextTextBox传递给.focus()?

假设您有一个静态的属性(意味着输出HTML元素的id是
txbTransferLedger
),那么您只需要将nextTextBox参数包含在选择器中即可(与当前使用的字符串
nextTextBox
相反):

更新:如果您无法使用静态的ClientIdMode,因此无法完全控制输入元素生成的ID,那么另一个选项是使用类选择器。为每个输入元素指定一个唯一的类名(这可以是您正在使用的任何现有类之外的名称),例如:


不确定“将参数nextTextBox传递给.focus()”是什么意思?我只是不明白当我的参数名为nextTextBox时,如何让我的javascript关注下一个文本框(TXB TransferLedger)。好的,我明白了。然后请查看Luke的答案。我不能将ClientMode设置为静态。那么我还有什么其他选项?
$('#' + nextTextBox).focus();
<asp:TextBox ID="txbTransferLedger" CssClass="AutoFill TransferLedger" />
$('input.' + nextTextBox).focus(); // e.g. $('input.TransferLedger').focus();