我想知道是否可以将html声明为变量。换句话说,是这样的:

$(document).ready(function(){

  var Bold="Yes!  There is bold in the text above!!";
  var NoBold="No... There isn't any bolded text in the paragraph above..";
  var BoldButton="<input class="BoldButton" type="button" value="bold" id="WelcomeBoldButton">";

  $(BoldButton)
  .insertAfter('#intro');

});

然后,使用.insertAfter操作,以不同的间隔将其放入我的页面:
$(BoldButton).insertAfter(#'intro');

这似乎不起作用,但是我是否接近某些东西?

最佳答案

您的引号放错了位置。

这个:

$(BoldButton).insertAfter(#'intro');

应该:
$(BoldButton).insertAfter('#intro');

如果只需要双引号,则可以这样将其转义:
var BoldButton="<input class=\"BoldButton\" type=\"button\" value=\"bold\" id=\"WelcomeBoldButton\">";

08-25 09:47