jquery怎么输出html代码


本文摘自PHP中文网,作者coldplay.xixi,侵删。

jquery输出html代码的方法:1、直接输出标签元素,代码为【var form1 = "<form id=\"myform\" method=\"post\" >"】;2、输出带变量的标签元素,代码为【var country =....】。

jquery输出html代码的方法:

形式一:直接输出标签元素

1.采用转义符号

1

2

3

4

var form1 = "<form id=\"myform\" method=\"post\" >"

+"<input type=\"text\" name=\"uname\"  style=\"height:20px;width:100%;\" />"

+"<input type=\"password\" name=\"pwd\" style=\"height:20px;width:100%;\" />"

+"</form>";

2.采用单引号

1

2

3

4

var form2  = '<form id="myform" method="post" >'

+'<input type="text" name="uname"  style="height:20px;width:100%;" />'

+'<input type="password" name="pwd" style="height:20px;width:100%;" />'

+'</form>';

3.采用es6的模板字符量(不过我喜欢用模板字符串来称呼这个。。。)

就是在前后都加上了一个( ` ),它中间就写你要输出的东西,写标签就输出标签,写\n就表示换行,写变量的话是不会输出变量代表的值,而是把变量的名字给输出来。比如说变量country的值为“中国”,那么它不会输出中国这个值,而是country变量名,要输出值的话请看 形式二。

1

2

3

4

var form3 = `<form id="myform" method="post">

   <input type="text" name="uname" style="height:20px;width:100%;" />

   <input type="password" name="pwd" style="height:20px;width:100%;" />

 </form>`

形式二:输出带变量的标签元素

1.采用转义符号

阅读剩余部分

相关阅读 >>

jQuery和zepto是什么?

jQuery与ajax的区别是什么

jQuery css()和attr()的区别是什么

vs如何安装jQuery

jQuery ligerui是什么?

jQuery获取元素到顶部距离的方法

jQuery有哪些选择器

jQuery的插件有哪些

jQuery如何给p标签赋值

实例讲解jQuery与js实现ajax

更多相关阅读请进入《jQuery》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...