jquery怎么输出html代码

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

临西网站建设公司创新互联公司,临西网站设计制作,有大型网站制作公司丰富经验。已为临西1000+提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的临西做网站的公司定做!

jquery输出html代码的方法:

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

1.采用转义符号

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.采用单引号

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变量名,要输出值的话请看 形式二。

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.采用转义符号

var country = "中国"; var table = "<table border=\\"1\\" style=\\"width:100%;\\">"; table += "<caption>国家信息列表</caption>"; table += "<thead><tr><th>ID</th><th>Name</th></tr></thead>"; table += "<tbody><tr><td>1</td><td>"+country+"</td></tr></tbody>"; table += "</table>";

2.采用单引号

var country = "中国"; var table = \'<table border="1" style="width:100%;">\'; table += \'<caption>国家信息列表</caption>\'; table += \'<thead><tr><th>ID</th><th>Name</th></tr></thead>\'; table += \'<tbody><tr><td>1</td><td>"\'+country+\'"</td></tr></tbody>\'; table += \'</table>\';

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

输出变量的值,比如上面说到的country=“中国”,那么要怎么才可以输出中国这个值呢?

其实可以用占位符来代表${ },括号中间的部分就写上你要输出变量所代表的变量名称。

var country = "中国"; var table = `<table border="1" style="width:100%;">`; table += `<caption>国家信息列表</caption>`; table += `<thead><tr><th>ID</th><th>Nane</th></tr></thead>`; table += `<tbody><tr><td>1</td><td>${country}</td></tr></tbody>`; table += `</table>`;

名称栏目:jquery怎么输出html代码
本文网址:https://www.cdcxhl.com/article2/cpsiic.html

成都网站建设公司_创新互联,为您提供Google响应式网站微信小程序企业网站制作网站建设自适应网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司