【发布时间】:2015-04-30 23:06:06
【问题描述】:
我有:
<body marginwidth="0" marginheight="0" contenteditable="true"
class="bootsy required form-control bootsy_text_area wysihtml5-editor"
spellcheck="true"
style="color: rgb(85, 85, 85); cursor: auto; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; line-height: 20px; letter-spacing: normal; text-align: start; text-decoration: none; text-indent: 0px; text-rendering: auto; word-break: normal; word-wrap: break-word; word-spacing: 0px; background-color: rgb(255, 255, 255);">
</body>
我使用了以下代码,但它不起作用:
if ($("body").hasClass("wysihtml5-editor")) {
$("body").html('this is a test content.');
});
我在我的 Rails 应用程序中使用 bootsy,它会在浏览器的源代码中生成这个 body 标签。所以,我想先用 class 找出这个 body 标签,然后使用 jquery 为其设置一些值。请帮帮我。
【问题讨论】:
-
您只能设置用于用户输入的元素的值。你真正想改变什么?
-
最后的额外关闭标签是干什么用的?
-
您的代码中的
this是什么?如果该代码在事件处理程序中,this将是事件的目标,而不是主体。如果要设置body的内容,为什么不写$("body").html()呢? -
先生,仍然没有得到 中的 html。
标签: javascript jquery html css ruby-on-rails