简体   繁体   English

如何从名称中使用jQuery显示/隐藏文本框?

[英]how can use jquery show/hide text box from name?

my textbox names is 我的文本框名称是
exm: <input name="packageconfigoption[2]" size="20" value="" type="text"> packageconfigoption[X], X is a number, and not have ID exm: <input name="packageconfigoption[2]" size="20" value="" type="text"> packageconfigoption [X],X是一个数字,没有ID
how can i show and hide input from this name? 如何显示和隐藏此名称的输入?
i used this code, but not work, have syntax error 我使用了此代码,但不起作用,有语法错误

    $('input[packageconfigoption[6]]').click(function() {
    if($(this).val() == "Exm1") {
        $('input[packageconfigoption[13]]').hide();
    } else {
        $('input[packageconfigoption[8]]').show();
    }
    });

i want if packageconfigoption[8] value changed, packageconfigoption[x] hide or show 我想要如果packageconfigoption [8]的值更改,packageconfigoption [x]隐藏或显示

The correct selectors that you use in your query would be input[name="packageconfigoption[6]"] , etc., not what you currently have. 您在查询中使用的正确选择器将是input[name="packageconfigoption[6]"]等,而不是您当前拥有的选择器。

In other words the attribute name name is what goes inside the brackets, and then it's set to the attribute value via an = symbol: 换句话说,属性名称是括号内的name ,然后通过=符号将其设置为属性值:

element[attribute="attribute_value"]

Right now what you have is a query looking for an input element with an attribute of packageconfigoption[6] , not an attribute of name with a value equal to packageconfigoption[6] . 现在,您所拥有的是一个查询,该查询正在寻找具有packageconfigoption[6]属性的input元素,而不是name等于packageconfigoption[6]值的属性。

You can use like this using Attribute Equals Selector [name=”value”] : 您可以使用Attribute Equals Selector [name =” value”]这样使用:

$('input[name="packageconfigoption[6]"]').click(function () {
    if ($(this).val() == "Exm1") {
        $('input[name="packageconfigoption[13]"]').hide();
    } else {
        $('input[name="packageconfigoption[8]"]').show();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM