如何在jQuery选择器中跳转〜字符[复制](How to escape ~ character in jQuery selector [duplicate])

编程入门 行业动态 更新时间:2024-10-28 02:21:25
如何在jQuery选择器中跳转〜字符[复制](How to escape ~ character in jQuery selector [duplicate])

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

需要在jQuery选择器字符串中跳出一个特殊字符 7个答案

我试图用这种方式选择一个元素

$('#QR~QID345')

因为元素的ID是QR~QID345但选择器不能与~工作,是否有任何修复?

在这种情况下更改ID不是一个选项。

This question already has an answer here:

Need to escape a special character in a jQuery selector string 7 answers

I'm trying to select an element this way

$('#QR~QID345')

because the element's id is QR~QID345 but the selector doesn't work with ~, is there any fix?

Changing the id is not an option in this case.

最满意答案

你可以逃避~

alert( $('#QR\\~QID345').text() ); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="QR~QID345">Hello</div> 
  
 

You can escape ~ with \\

alert( $('#QR\\~QID345').text() ); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="QR~QID345">Hello</div> 
  
 

更多推荐

本文发布于:2023-07-06 20:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1054528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳转   字符   器中   如何在   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!