HTML:
<p class="greeting"> hello,my name is kevin. what's yours? </p>
jQuery的:
$("p.greeting").filter(function (){ return $this.text() === "my name is"; }).css("background","green");
我试图在< p class =“greeting”>中隔离“我的名字是”这几个字.标签.任何人都可以帮助我使用jQuery,因为它似乎不起作用.谢谢.
解决方法
干得好:
CSS:
.highlight { background-color: yellow; }
JavaScript的:
var text = 'My namE iS'; $( 'p.greeting' ).html( function ( i,html ) { var regexp,replacement; regexp = RegExp( '(' + text + ')','gi' ); replacement = '<span class="highlight">$1</span>'; return html.replace( regexp,replacement ); });