jquery输出html代码的方法:1、直接输出标签元素,代码为【var form1 = "<form id=\\\\"myform\\\\" method=\\\\"post\\\\" >"】;2、输出带变量的标签元素,代码为【var country =….】。
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>`;
linux云服务器怎么选择系统能查一下我的更改管理局呢边怎样了嘛制作ppt用什么软件免费 免费制作ppt的软件推荐“姚劲波”域名中五位交易百度云服务器忙碌TestLink-1.9.16邮箱配置(网易163)请问你们服务器漏洞可以修复吗第三方检测说有漏洞如何用SMART原则来进行SEO项目呢