jquery怎么输出html代码


当前第2页 返回上一页

1

2

3

4

5

6

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

1

2

3

4

5

6

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=“中国”,那么要怎么才可以输出中国这个值呢?

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

1

2

3

4

5

6

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

相关免费学习推荐:JavaScript(视频)

以上就是jquery怎么输出html代码的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

jQuery中getjson乱码怎么办

jQuery怎么样判断是否为空

jQuery如何判断元素是否隐藏

jQuery ui datepicker时间控件的用法(三)

jQuery怎么删除select选项?

jQuery如何查找指定元素的父类

jQuery怎样才能确定滚动事件的方向

jQuery中怎样实现两秒之后刷新页面

jQuery怎么动态修改css样式

jQuery如何获取class的值

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




打赏

取消

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

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

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

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

评论

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