jquery怎么输出html代码

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>`;

更多关于云服务器域名注册,虚拟主机的问题,请访问三五互联官网:www.35.com

赞(0)
声明:本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。邮箱:3140448839@qq.com。本站原创内容未经允许不得转载,或转载时需注明出处:三五互联知识库 » jquery怎么输出html代码

登录

找回密码

注册