Asp.net mvc 4 使用“文本区域只读”时出现问题;所见即所得的HTML5“;自举
我已尝试在MVC4应用程序中使文本区域为只读 但当我使用以下代码时,它始终处于启用编辑状态:Asp.net mvc 4 使用“文本区域只读”时出现问题;所见即所得的HTML5“;自举,asp.net-mvc-4,wysihtml5,Asp.net Mvc 4,Wysihtml5,我已尝试在MVC4应用程序中使文本区域为只读 但当我使用以下代码时,它始终处于启用编辑状态: @Html.TextAreaFor(model => model.EndUserHelp, new { id = "name1", @class = "editorHelp"}) $('#name1').wysihtml5({ "font-styles": true, "emphasis": true,
@Html.TextAreaFor(model => model.EndUserHelp, new { id = "name1", @class = "editorHelp"})
$('#name1').wysihtml5({
"font-styles": true,
"emphasis": true,
"lists": true,
"html": false,
"link": true,
"image": true,
"color": false,
"useLineBreaks": true
});
$("#name1").prop('readonly', true);
无法将该区域设置为只读。您可以在初始化编辑器的位置添加以下代码。 我在版本0.3.0中也遇到了同样的问题,我做了这个来修复它
function enforceInactiveStates() {
var disabled = this.textareaElement.disabled;
var readonly = !!this.textareaElement.getAttribute('readonly');
if (readonly) {
this.composer.element.setAttribute('contenteditable', false);
this.toolbar.commandsDisabled = true;
}
if (disabled) {
this.composer.disable();
this.toolbar.commandsDisabled = true;
}
}
editor.on( 'load', enforceInactiveStates );
请注意,“只读”与“已禁用”不同。请尝试以下操作:
$editor = $(".textarea-disabled").wysihtml5();
$editor.attr('disabled', 'disabled');
使用'disabled'
而不是'readonly'