Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ID为1的Select的jQuery选择器_Jquery_Jquery Selectors - Fatal编程技术网

ID为1的Select的jQuery选择器

ID为1的Select的jQuery选择器,jquery,jquery-selectors,Jquery,Jquery Selectors,我有以下带有异常ID/Name属性的select: <select name="customfield_10021:1" id="customfield_10021:1" class="select cascadingselect-child"> 如何选择此字段?我以前从未见过这种特殊的语法,但它显然适用于submit 谢谢 Jared你应该逃出结肠,所以要这样做: $("#customfield_10021\\:1") 你应该: unit = $('#customfield_1

我有以下带有异常ID/Name属性的select:

<select name="customfield_10021:1" id="customfield_10021:1" class="select cascadingselect-child">
如何选择此字段?我以前从未见过这种特殊的语法,但它显然适用于submit

谢谢


Jared

你应该逃出结肠,所以要这样做:

$("#customfield_10021\\:1")
你应该:

unit = $('#customfield_10021\\:1 option:selected').text();
这是因为冒号是一个特殊字符,需要用反斜杠转义。 希望这有帮助。干杯

逃离结肠:

unit = $('#customfield_10021\\:1 option:selected').text();

而不是使用option:selected,您可能只想使用它来获取以下值:

逃逸:通过使用\\

或者可以使用document.getElementByIdcustomfield_10021:1作为选择器的上下文

var s = document.getElementById("customfield_10021:1");
unit2 = $('option:selected', s).text();

请记住,冒号用于删除伪类,就像使用option:selected一样,您必须从元素的id中删除冒号:

<select name="customfield_10021_1" id="customfield_10021_1" class="select cascadingselect-child">
这是因为jQuery试图将customfield_10021:1用作id=customfield_10021,而伪类1不存在,因此出现了错误

试试这个:

unit = $('#customfield_10021\\:1 option:selected').text();
:通常用于伪选择器,反斜杠需要在字符串文本中加倍

为避免疑义,请在ID和Name属性中使用冒号字符。

此功能:

$('[id="customfield_10021:1"] option:selected').text()
现场演示:

我认为这是可行的:

unit = $("#customfield_10021\\:1 option:selected").text();

JSF中的另一个解决方案是防止表单名称在每个id前面加前缀

这可以通过表单标记中的prependId=false完成:

            <h:form id="gestion_clefs" prependId="false">

看一下文档:谢谢大家的回复。问题出在两耳之间,因为我更关注不寻常的ID/Name属性,而不是选择器语法。对!唯一的问题是我不能删除冒号这是JIRA系统中的一个自定义字段。然后你必须按照其他人的建议转义冒号。这个答案是错误的-他不必删除冒号。他只能逃避它。不,我需要文本;这个值是一个文本值的索引。好的,只是想确保你没有把事情过度复杂化。这是一个有趣的方法。我想这将消除冒号被解释为选择器的情况。@Jared是的,我相信是这样。属性选择器中的引号确保字符串确实是一个名称,而不是另一个选择器。
unit = $('#customfield_10021\\:1 option:selected').text();
$('[id="customfield_10021:1"] option:selected').text()
unit = $("#customfield_10021\\:1 option:selected").text();
            <h:form id="gestion_clefs" prependId="false">