如何在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 answersI'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>
更多推荐
发布评论