未捕获错误:语法错误,无法识别的表达式:unsupported pseudo:[duplicate]

时间:2022-11-07 18:38:58

This question already has an answer here:

这个问题在这里已有答案:

i have an txtBox and its id is : beginDateTxt

我有一个txtBox,它的ID是:beginDateTxt

but jsf makes it j_idt8:beginDateTxt

但是jsf使它成为j_idt8:beginDateTxt

in jquery i try to reach it like that

在jquery我尝试达到它那样

  <script type="text/javascript">
            $(document).ready(function() {
                $(function() {
                    $("#j_idt8:beginDateTxt").mobiscroll().date({
                       theme: 'android-ics light', mode:'scroller', display: 'bottom'
                    });
                });

            });
   </script>

but i get below error:

但我得到以下错误:

Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: beginDateTxt

未捕获错误:语法错误,无法识别的表达式:unsupported pseudo:beginDateTxt

why?

2 个解决方案

#1


57  

You could try

你可以试试

$(document.getElementById('j_idt8:beginDateTxt')).mobiscroll().date({theme: 'android-ics light', mode:'scroller', display: 'bottom'});

In general jQuery uses something like CSS selectors in its $() function. In a CSS selector the : denotes a pseudo-class. However, in your case the : is just a part of the id.

通常,jQuery在其$()函数中使用类似CSS选择器的东西。在CSS选择器中,:表示伪类。但是,在您的情况下,:只是id的一部分。

If you use the generic getElementById(), the argument is not decomposed, but seen as an ID altogether. So by using getElementById() and wrapping the result with $() you can circumvent this "misunderstanding".

如果使用泛型getElementById(),则参数不会被分解,而是完全被视为ID。因此,通过使用getElementById()并使用$()包装结果,您可以避免这种“误解”。

In general, however, I think it would be better to change the namespacing scheme in your JSF.

但是,一般来说,我认为更改JSF中的命名空间方案会更好。

EDIT

The jQuery documentation on selectors states that you should escape special characters by the use of \\:

选择器上的jQuery文档声明您应该通过使用\\来转义特殊字符:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").

要使用任何元字符(例如!“#$%&'()* +,。/:; <=>?@ [] ^`{|}〜)作为名称的文字部分,必须使用两个反斜杠进行转义:\。例​​如,id =“foo.bar”的元素可以使用选择器$(“#foo \\。bar”)。

This will lead to the answer already given by Daniel, which in my opinion is superior to the answer given above. The explanation, however, remains valid.

这将导致丹尼尔已经给出的答案,我认为这个答案优于上面给出的答案。但是,解释仍然有效。

$("#j_idt8\\:beginDateTxt").mobiscroll().date({theme: 'android-ics light', mode:'scroller', display: 'bottom'});

#2


27  

If you want to use jQuery id selector you need to escape the : with \ and then to escape the \ (double escape)

如果你想使用jQuery id选择器你需要转义:with \然后转义\(双转义)

Here:

$(function() {
    $("#j_idt8\\:beginDateTxt").mobiscroll().date({
        theme: 'android-ics light',
        mode:'scroller', display: 'bottom'
    });
});

#1


57  

You could try

你可以试试

$(document.getElementById('j_idt8:beginDateTxt')).mobiscroll().date({theme: 'android-ics light', mode:'scroller', display: 'bottom'});

In general jQuery uses something like CSS selectors in its $() function. In a CSS selector the : denotes a pseudo-class. However, in your case the : is just a part of the id.

通常,jQuery在其$()函数中使用类似CSS选择器的东西。在CSS选择器中,:表示伪类。但是,在您的情况下,:只是id的一部分。

If you use the generic getElementById(), the argument is not decomposed, but seen as an ID altogether. So by using getElementById() and wrapping the result with $() you can circumvent this "misunderstanding".

如果使用泛型getElementById(),则参数不会被分解,而是完全被视为ID。因此,通过使用getElementById()并使用$()包装结果,您可以避免这种“误解”。

In general, however, I think it would be better to change the namespacing scheme in your JSF.

但是,一般来说,我认为更改JSF中的命名空间方案会更好。

EDIT

The jQuery documentation on selectors states that you should escape special characters by the use of \\:

选择器上的jQuery文档声明您应该通过使用\\来转义特殊字符:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").

要使用任何元字符(例如!“#$%&'()* +,。/:; <=>?@ [] ^`{|}〜)作为名称的文字部分,必须使用两个反斜杠进行转义:\。例​​如,id =“foo.bar”的元素可以使用选择器$(“#foo \\。bar”)。

This will lead to the answer already given by Daniel, which in my opinion is superior to the answer given above. The explanation, however, remains valid.

这将导致丹尼尔已经给出的答案,我认为这个答案优于上面给出的答案。但是,解释仍然有效。

$("#j_idt8\\:beginDateTxt").mobiscroll().date({theme: 'android-ics light', mode:'scroller', display: 'bottom'});

#2


27  

If you want to use jQuery id selector you need to escape the : with \ and then to escape the \ (double escape)

如果你想使用jQuery id选择器你需要转义:with \然后转义\(双转义)

Here:

$(function() {
    $("#j_idt8\\:beginDateTxt").mobiscroll().date({
        theme: 'android-ics light',
        mode:'scroller', display: 'bottom'
    });
});