用于ID为1的jQuery选择器 [英] jQuery Selector for Select with ID:1
本文介绍了用于ID为1的jQuery选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我选择了以下具有不寻常的ID/名称属性的选择:
I have the following select with an unusual ID/Name attribute:
<select name="customfield_10021:1" id="customfield_10021:1" class="select cascadingselect-child">
这似乎不允许我选择:
unit = $('#customfield_10021:1 option:selected').text();
uncaught exception: Syntax error, unrecognized expression: 1
如何选择此字段?我以前从未见过这种特殊的语法,但显然可以在Submit上使用.
How can I select this field? I've never even seen this particular syntax before, but it apparently works on submit.
谢谢!
讨厌
推荐答案
使用\\
unit2 = $('#customfield_10021\\:1 option:selected').text();
Updated jsfiddle
或者您可以将document.getElementById("customfield_10021:1")
用作选择器的上下文.
Or you can use document.getElementById("customfield_10021:1")
as the context for your selector.
var s = document.getElementById("customfield_10021:1");
unit2 = $('option:selected', s).text();
这篇关于用于ID为1的jQuery选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文