我正在尝试在我的网页中实现QUILL.JS WYSIWYG编辑器。我不知道如何将HTML从编辑器变成一个可以存储在我的数据库中的可用变量。
ASPX
<div id="quill-editor"></div>
<asp:Button ID="Button1" CssClass="btn btn-primary" runat="server" OnClientClick="returnString();" Text="Ssubmit" onclick="Button1_Click" />
<asp:HiddenField ID="hdnResultValue" Value="0" runat="server" />
JS On ASPX
<script>
document.addEventListener("DOMContentLoaded", function(event) {
if (!window.Quill) {
return $('#quill-editor,#quill-toolbar,#quill-bubble-editor,#quill-bubble-toolbar').remove();
}
var editor = new Quill('#quill-editor', {
modules: {
toolbar: '#quill-toolbar'
},
placeholder: 'Type something',
theme: 'snow'
});
</script>
如何将HTML输出存储到隐藏字段中,以便我可以在我的代码中检索它?
谢谢
在隐藏字段中设置ClientIDMode =“Static”
<asp:HiddenField runat="server" ID="hdnResultValue" ClientIDMode="Static" />
然后从jquery:
$("#hdnResultValue").val("test");
通过启用ClientIdMode static,您将能够通过id访问该字段。其他明智的你必须使用以下方式,因为asp标签的客户端ID是生成一个。
var textbox = document.getElementById('<%= hdnResultValue.ClientID %>');
从代码背后
hdnResultValue.Value.ToString();