程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> jquery-這是什麼選擇器:var txt2=$(<p></p>).text(Text.);???

jquery-這是什麼選擇器:var txt2=$(<p></p>).text(Text.);???

編輯:編程解疑
這是什麼選擇器:var txt2=$("<p></p>").text("Text.");???

源碼:

 <!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
function appendText()
{
var txt1="<p>Text.</p>";              // Create text with HTML
var txt2=$("<p></p>").text("Text.");  // Create text with jQuery
var txt3=document.createElement("p");
txt3.innerHTML="Text.";               // Create text with DOM
$("body").append(txt1,txt2,txt3);        // Append new elements
}
</script>
</head>
<body>

<p>This is a paragraph.</p>
<button onclick="appendText()">Append text</button>

</body>
</html>

這其中的

 $("<p></p>").text("Text."); 中 $("<p></p>") 

這是什麼意思?

最佳回答:


  $("<p></p>")

這是jquery中通過html代碼片段產生一個元素的方法。

bogexueqianduan
caozhy
bogexueqianduan
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved