使用jQuery处理元素ID中的冒号 [英] Handling colon in element ID with jQuery

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

问题描述

我们无法使用jQuery在JS代码中访问ID为"test:abc"的div元素.

We are not able to access the div element with ID "test: abc" in JS code using jQuery.

<div id="test:abc">

$('#test:abc') 

没有冒号就可以正常工作.我们无法控制ID的生成,因为它会以特立尼达子表格的形式自动生成,因为它会将带有:的子表格ID附加到其中的每个元素.

It's working fine without colon. We do not have control on ID generation as it is auto generated in Trinidad sub forms because it attaches sub form ID with : to every element inside it.

推荐答案

您需要使用两个反斜杠来使冒号转义:

You need to escape the colon using two back-slashes:

$('#test\\:abc')

这篇关于使用jQuery处理元素ID中的冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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