.append() 方法不适用于 <span>

.append() method doesn't works with &nbsp; in <span>

有以下代码:

$("[id$='somelement_detection']").parent().parent().append("<span id='checkspan_button' class='checkspan checkspan_unchecked'/>&nbsp;</span>");

但它产生了错误的输出:

<span class="checkspan checkspan_unchecked" id="checkspan_button"></span> 

没有 &nbsp; 我无法在 IE 中使用此跨度进行某些操作。 有什么建议吗?

您错误地关闭了 span 标签。试试不用 <span/>

$("[id$='somelement_detection']").parent().parent().append("<span id='checkspan_button' class='checkspan checkspan_unchecked'>&nbsp;</span>");

您也可以添加 space 而不是  

$("[id$='somelement_detection']").parent().parent().append("<span id='checkspan_button' class='checkspan checkspan_unchecked'> </span>");

或者,您可以使用这个:

$("<span/>",{
   id: "checkspan_button",
   class: "checkspan checkspan_unchecked",
   html: "&nbsp;"
}).appendTo($("[id$='somelement_detection']").parent().parent())