如何通过名称引用元素并带有[]括号? [英] How do I reference an element by name with [] brackets in it?

查看:118
本文介绍了如何通过名称引用元素并带有[]括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jquery BY NAME中引用其中包含[]的元素。

How do you reference a element in jquery BY NAME that has the [] in it.

<select name="values[]" multiple="true">
<option value="1">1</option>
<option value="2">2</option>
<option value="2">2</option>
</select>

<script type="text/javascript">
$('[name=values[]]'); 
</script>

这应该抓住元素,但它不起作用,我相信名字中的[]是弄乱了它,逃避它似乎也没有用。我无法弄清楚我做错了什么

this should grab the element, but it does not work, I believe the [] in the name is messing it up, escaping it doesn't seem to work either. I can't figure out what I'm doing wrong

推荐答案

一种方法是在选择器中引用名称:

One way is to quote the name in the selector:

$('[name="values[]"]')

或者:

$("[name='values[]']")

这篇关于如何通过名称引用元素并带有[]括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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