Jquery选择带冒号的ID [英] Jquery selecting an ID with a colon in it

查看:125
本文介绍了Jquery选择带冒号的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为网站编写预先编写的模块,我需要定位一个id为 test的元素:两个。现在,这个元素中有一个冒号,所以jquery可能是可以理解的,将'two'看作伪类。有没有办法用jQuery定位这个元素?

I'm working on a pre-written module for a site, and I need to target an element with the id test:two. Now, this element has a colon in it, so jquery is presumably and understandably seeing the 'two' as a pseudo class. Is there any way of targeting this element with jQuery?

此外,无法更改ID。相信我,如果可以的话。

Also, changing the ID is not possible. Believe me, if I could I would.

我在这里举了一个例子: http://jsfiddle.net/zbX8K/1/

I've put together an example here: http://jsfiddle.net/zbX8K/1/

推荐答案

简单地逃脱冒号 \\

$('#test\\:two');

http: //jsfiddle.net/zbX8K/3/

查看文档: 如何通过具有CSS表示法中使用的字符的ID选择元素?

See the docs: How do I select an element by an ID that has characters used in CSS notation?.

这篇关于Jquery选择带冒号的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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