本文摘自PHP中文网,作者coldplay.xixi,侵删。
jquery生成元素的方法:1、加入代码【$("html代码")】;2、使用html函数,html函数是修改元素中的html代码,可以做到创建元素。

本教程操作环境:windows10系统、jquery2.2.4,本文适用于所有品牌的电脑。
推荐:《jquery视频教程》
jquery生成元素的方法:
创建元素
方法1:$("html代码")
方法2:或者使用html函数,html函数是修改元素中的html代码,也可以做到创建元素
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<title>title</title>
<style>
div {
width: 300px;
height: 200px;
border: 1px solid red;
}
</style>
<script src= "jquery-1.12.1.js" ></script>
<script>
$( function () {
$( "#btn" ).click( function () {
$( "<input type='button' value='按钮'>" ).appendTo($( "#dv" ));
});
$( "#btn" ).click( function () {
$( "#dv" ).html( "<input type='button' value='按钮'>" );
});
});
</script>
</head>
<body>
<input type= "button" value= "创建一个按钮" id= "btn" />
<div id= "dv" >
小苏凑合有点帅吧
</div>
</body>
</html>
|
相关免费学习推荐:JavaScript(视频)
以上就是jquery怎么生成元素的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
jQuery不兼容低版本ie浏览器怎么办
jQuery post与ajax区别
jQuery 空格怎么去除
html5和jQuery实现弹出创意搜索框层的方法
jQuery怎么遍历list集合
ajax与jQuery的区别是什么
jQuery 如何通过文本查找元素
jQuery三大版本之间有什么区别?
jQuery的插件有哪些
jQuery怎么锁定焦点
更多相关阅读请进入《jQuery》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » jquery怎么生成元素