用于名称属性中带有方括号的输入的 jQuery 选择器 [英] jQuery selector for inputs with square brackets in the name attribute

查看:45
本文介绍了用于名称属性中带有方括号的输入的 jQuery 选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择在 name 属性中有方括号的这个元素:

I'm trying to select this element which has square brackets in the name attribute:

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

我试过这个(不起作用):

I've tried this (which doesn't work):

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

这也不行:

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

或者这个:

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

正如你们中的一些人指出的那样,$('input[inputName=someValue]') 永远不会工作.我试图做的是:$('input[name=inputName][value=someValue]').(但在 name 属性中使用 []).

As some of you have pointed out, $('input[inputName=someValue]') would never work. What I was trying to do was: $('input[name=inputName][value=someValue]'). (But with [] in the name attribute).

推荐答案

根据 jQuery 文档,试试这个:

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

但是,我不确定这是否适合您的选择器的语法.你可能想要:

However, I'm not sure that's the right syntax for your selector. You probably want:

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

这篇关于用于名称属性中带有方括号的输入的 jQuery 选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆