为什么使用变量:contains()不起作用?有什么办法可以使它工作吗? filter('contains()')
也没有工作。jquery:包含使用变量的选择器
<h2>Test</h2>
<div>Test</div>
var model = $('h2').text();
//variable doesn't work
$('div:contains(model)').css('background','yellow');
//obviously, string works
$('div:contains("Test")').css('background','yellow');
Dupl icated:看到答案在这里:http://stackoverflow.com/questions/2191419/jquery-contains-with-a-variable-syntax – gongzhitaao 2013-03-20 19:20:29
与文本节点无关,JS不解析字符串内的变量(看起来像你可能会用到PHP?)您必须使用'$('div:contains('+ $ modele +')')。css('background','yellow');' – Adrian 2013-03-20 19:20:48
非常感谢! – veksen 2013-03-20 20:06:56