这个 HTML:
<div class="editable" contentEditable="true">
<span class="empty">change me</span>
</div>
和这个 JQuery:
$(".empty").click(function() {
$(this).css("color","#000");
$(this).html(" ");
});
没有像我希望的那样工作(或根本没有)。我想这样做,当用户单击跨度中的“更改我”文本时,字体颜色变为黑色并且跨度中的现有文本消失。
最佳答案
这是行不通的,因为跨度没有高度属性,在清空它的内容后,它将有一个 width of 0px
。和一个 height of 0px
.将跨度替换为 <div>
并在你的CSS中给它一个高度。
此处示例:http://jsfiddle.net/JftGd/12/
关于jquery:更改 css 并删除 html 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11826352/