zl程序教程

您现在的位置是:首页 >  前端

当前栏目

jquery创建一个新的节点对象(自定义结构/内容)的好方法

jQuery节点方法对象 一个 创建 结构 自定义
2023-06-13 09:14:44 时间
HTML
复制代码代码如下:

<!DOCTYPEhtml>
<html>
<head>
<scriptclass="jsbin"src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<metacharset=utf-8/>
<title>JsBin-在线js/css调试工具</title>
<!--[ifIE]>
<scriptsrc="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article,aside,figure,footer,header,hgroup,
menu,nav,section{display:block;}
</style>
</head>
<body>
<pid="hello">HelloOSTools</p>
</body>
</html>

JavaScript
复制代码代码如下:

//jq创建一个新的节点对象;
//例如:<divid="mydiv"class="menu"></div>
varobjNewDiv=$("<div>",{"id":"mydiv","class":"menu"});
objNewDiv.html(123456);
$("#hello").append(objNewDiv);
console.log(objNewDiv);

结果