Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

javascript - jQuery选择器,用于在name属性中带有方括号的输入(jQuery selector for inputs with square brackets in the name attribute)

I'm trying to select this element which has square brackets in the name attribute:(我试图选择在name属性中具有方括号的此元素:)

<input type="text" name="inputName[]" value="someValue">

I've tried this (which doesn't work):(我已经尝试过了(这不起作用):)

$('input[inputName[]=someValue]')

and neither does this:(而且也不是:)

$('input[inputName&#91;&#93;=someValue]')

or this:(或这个:)

$('input["inputName[]"=someValue]')

EDIT: As some of you have pointed out, $('input[inputName=someValue]') would never work.(编辑:正如你们中有些人指出的那样, $('input[inputName=someValue]')将永远无法工作。)

What I was trying to do was: $('input[name=inputName][value=someValue]') .(我想做的是: $('input[name=inputName][value=someValue]') 。) (But with [] in the name attribute).((但在name属性中使用[] )。)   ask by aidan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Per the jQuery documentation , try this:(根据jQuery文档 ,请尝试以下操作:)

$('input[inputName\[\]=someValue]')

[EDIT] However, I'm not sure that's the right syntax for your selector.([EDIT]但是,我不确定这是您选择器的正确语法。)

You probably want:(您可能想要:)
$('input[name="inputName[]"][value="someValue"]')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...