日期:2014-05-17 浏览次数:20707 次
$(":contains('感谢了')").css("color","red");
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <script src="http://code.jquery.com/jquery-latest.js"></script> <style> </style> </head> <body> <div>123感谢了123</div> <div>感谢了</div> <div>123感谢了</div> <script> var r = /^感谢了$/; $('div').each(function(){ var h = $(this).html(); if( r.test(h) ){ $(this).html('<span style="color:red;">'+h+'</span>'); } }) </script> </body> </html>
------解决方案--------------------
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <script src="http://code.jquery.com/jquery-latest.js"></script> <style> </style> </head> <body> <div>123感谢了123</div> <div>感谢了</div> <div>123感谢了</div> <script> $('div').each(function(){ var h = $(this).html(); $(this).html( h.replace('感谢了', '<span style="color:red;">感谢了</span>') ); }) </script> </body> </html>