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(){
           //匹配内容中包含a选择器的所有li
            $("li:has(a)").html(‘水浒传‘);
            });
        };
  </script>
 </head>
 <body>

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

    <hr/>
  <input type="button" id=‘btnOk‘ value=‘确定‘  />
 </body>
</html>
时间: 2024-08-29 03:16:26

jquery内容选择器(匹配包含指定选择器的元素)的相关文章

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> &

jquery简单原则器(匹配除了指定选择器之外的元素 selector 表示选择器)

<!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> &

[ jquery 选择器 :nth-last-of-type() ] 选取指定(p)父元素下的从后向前数的指定第一个子元素(无关目标元素在父元素中所处的位置)

选取指定(p)父元素下的从后向前数的指定第一个子元素(无关目标元素在父元素中所处的位置): 实例: <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title> <meta http-equiv='description' content='this is my page'> <meta http-equiv='keywords' conte

js和jQuery判断数组是否包含指定元素

最近遇见一些前台基础性问题,在这里笔者觉得有必要记录一下,为了以后自己查阅或者读者查看. 已知var arr = ['java','js','php','C++']; 问题:arr数组是否包含'java'字符串?1.js方法来判断/** * 使用循环的方式判断一个元素是否存在于一个数组中 * @param {Object} arr 数组 * @param {Object} value 元素值 */function isInArray(arr,value){ for(var i = 0; i <

jQuery 遍历 - children() 方法 获取指定id下子元素的值

<a id="Aobj_2_2" class="" specid="2" specvid="2" href="javascript:void(0);"> <span>红色</span> <i title="点击"></i> </a> $("#Aobj_2_2").children("sp

匹配包含给定文本的元素

描述: 查找所有包含 "John" 的 div 元素 HTML 代码: <div>John Resig</div> <div>George Martin</div> <div>Malcom John Sinclair</div> <div>J. Ohn jQuery 代码: $("div:contains('John')") 结果: [ <div>John Resig&l

SqlSever基础 where % 可能存在一个字符或者多个字符,查询内容中是否包含指定字

镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ 1 code 1 --创建一个数据库 2 create database helloworld1 3 4 --用helloworld1这个数据库 5 use helloworld1 6 7 --创建一个表格teacher 8 create table Teacher 9 ( 10 Id int p

[attribute] 匹配包含给定属性的元素

描述: 查找所有含有 id 属性的 div 元素 HTML 代码: <div> <p>Hello!</p> </div> <div id="test2"></div> jQuery 代码: $("div[id]") 结果: [ <div id="test2"></div> ]

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> &