jQuery选择器不接受管道字符|? [英] jquery selector doesnt accept pipe character |?

查看:73
本文介绍了jQuery选择器不接受管道字符|?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要尝试调用的html ID.它具有特定的名称构建,例如name_|_anyting 但是当我尝试使用Jquery的选择器获取elemetn时,出现错误

I have an html ID I'm trying to call. It has a specific name build like this name_|_anyting but when I try to get the elemetn using Jquery's selectors I get an error

$("#name_|_anyting")

错误:语法错误,无法识别的表达式:| _anyting

Error: Syntax error, unrecognized expression: |_anyting

所以我的问题是: jQuery选择器中是否不允许使用管道字符作为ID?

so my question is : Are pipe characters not allowed as Ids in jquery selectors ?

推荐答案

|是选择器语法中的特殊字符,这意味着您不能直接在ID选择器中使用它.如果您无法更改标记中的ID以容纳选择器,则必须转义选择器以欺骗jQuery选择元素:

| is a special character in selector syntax, which means you can't use it directly in an ID selector. If you cannot change the ID in your markup to accommodate your selector, you'll have to make do with escaping the selector to trick jQuery into selecting the element anyway:

$("#name_\\|_anything")

这篇关于jQuery选择器不接受管道字符|?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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