yangzailu

导航

jquery内容选择器(根据内容匹配元素)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>内容选择器</title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <style type="text/css">
  .yang{ border-collapse: collapse; width:500px;height:30px;border:1px solid red;"}
  </style>
  <script  type="text/javascript" src="jquery-1.7.1.min.js"></script>
  <script type="text/javascript">
  /*
    :contains(text)    //根据内容匹配元素
    :empty   //匹配内容为空的元素
    :has(selector)  //匹配包含指定选择器的元素
    :parent //匹配内容不为空的元素
  */
        window.onload=function(){
        $('#btnOk').click(function(){
           //根据内容匹配元素
            $("li:contains('国')").html('水浒传');
            });
        };
  </script>
 </head>
 <body>

     <ol>
            <li>三国演义</li>
            <li>西游记</li>
            <li></li>
            <li>红楼梦</li>
     </ol>

    <hr/>
  <input type="button" id='btnOk' value='确定'  />
 </body>
</html>

 

posted on 2016-09-06 13:32  飞离地平线  阅读(1546)  评论(0编辑  收藏  举报