jquery包含对\不起作用的选择器(反斜杠)。请在下面找到代码
Java脚本:
$(document).ready(function(){
$("p:contains(Example:\\servername)").css("background-color", "yellow");
});
HTML
<p>Example:\\servername</p>
答案 0 :(得分:2)
expect(formatDate('2020-10-02')).toEqual('02.10.20');
expect(formatDate(1234567890000)).toEqual('14.02.09');
expect(formatDate([2020, 0, 1])).toEqual('01.01.20');
expect(formatDate(new Date(2014, 0, 1))).toEqual('01.01.14');
$(document).ready(function() {
$("p:contains('Example:\\\\\\\\\\servername')").css("background-color", "yellow");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>Example:\\servername</p>
$(document).ready(function() {
$("p:contains('Example:\')").css("background-color", "yellow");
});
答案 1 :(得分:1)
不幸的是,\
需要与另一个\
一起转义,我认为您不能使用:contains
选择器来实现。
您可以使用filter()
let p=$("p").filter(function(){
return $(this).text().includes('Example:\\\\servername')
}).css("background-color", "yellow");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>Example:\\servername</p>