您的位置:首页 > Web前端 > JQuery

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

2016-09-06 13:32 423 查看
<!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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐