简体   繁体   English

jquery 无法使用此 ID #tel / fax

[英]jquery is not working with this id #tel / fax

I'm using this id(tel / fax) in this line我在这一行中使用了这个 ID(电话/传真)

$("#" + val.target.id).attr('disabled', 'disabled');

then I get an error like:然后我收到如下错误:

Syntax error, unrecognized expression: #tel / fax语法错误,无法识别的表达式:#tel / fax

You cannot have spaces in id attribute. id 属性中不能有空格。 you can replace the space with any other character with replace() function.您可以使用 replace() 函数将空格替换为任何其他字符。

ID should be one word without spaces and special chars. ID 应该是一个没有空格和特殊字符的单词。 jQuery selecting works same as css selecting. jQuery 选择的工作方式与 css 选择相同。 For example, if you cannot write in your css #tel / fax {...} then you cannot do same in your jQuery - $('#tel / fax');例如,如果你不能在你的 css #tel / fax {...}写,那么你不能在你的 jQuery 中做同样的事情 - $('#tel / fax'); would throw you an error.会给你一个错误。

Just change your ID of element and it will work.只需更改您的元素 ID 即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM