天天看點

JQuery--dom捕獲html元素

text()方法捕獲div的文本
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
	</script>
	<script>
		$(document).ready(function()
			
		{
			$("#demo2").click(function(){
				alert($("#demo1").text())
			})
			
		})
	</script>
	</head>
	<body>
		<div id="demo1">hello jquery dom</div>
		<button id="demo2">點選顯示文本</button>
	</body>
</html>

           
text(“xxxx”)方法修改文本

效果類似于innerhtml

$("#demo3").click(function(){
				$("#demo1").text("hello the world")
			})
           

繼續閱讀