如何使用jquery动态构建包含多个<span>的.text节点

时间:2016-08-22 20:54:16

标签: jquery html

我想动态更新<h1>文字以包含<span></span>代码。

我的jsfiddle显示的javascript如下所示:

$("h1").text("Time Left:<span>" + padNum(glob.gameTimer) + "</span>Best:
<span>" + padNum(glob.bestTime) + "</span>Reaction Time:<span>" + 
padNum(glob.reactionTime) + "</span");

2 个答案:

答案 0 :(得分:1)

使用html代替text

$("h1").html("Time Left:<span>" + padNum(glob.gameTimer) + "</span>Best:<span>" + padNum(glob.bestTime) + "</span>Reaction Time:<span>" + padNum(glob.reactionTime) + "</span");

答案 1 :(得分:1)

只需使用$("h1").html()代替$("h1").text()