<!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:empty").html('水滸傳');
});
};
</script>
</head>
<body>
<ol>
<li>三國演義</li>
<li>西遊記</li>
<li></li>
<li>紅樓夢</li>
</ol>
<hr/>
<input type="button" id='btnOk' value='確定' />
</body>
</html>
更多專業前端知識,請上【猿2048】www.mk2048.com