我正在使用降价,并且我有一些输入,例如**test**
这使得单词 test 出现在粗体测试中,并且我已经将它转换为 html 像这样“
var converter1 = Markdown.getSanitizingConverter();
var editor1 = new Markdown.Editor(converter1);
editor1.run();
var d = document.getElementById("wmd_input");
var html = converter1.makeHtml(d.value);
alert(html);
这提醒<b>test</b>
问题是我需要获取这个值,即<b>test</b>
通过服务器端代码(asp.net)访问它。我尝试将它分配给这样的变量:
document.getElementById("Label1").value = html;
但它似乎不起作用,当我转到它背后的代码时,它显示Label1
为空。这可能吗?
编辑
我试图将其更改为隐藏字段相同的问题:
<script type="text/javascript">
(function () {
var converter1 = Markdown.getSanitizingConverter();
var editor1 = new Markdown.Editor(converter1);
editor1.run();
var d = document.getElementById("wmd_input");
var html = converter1.makeHtml(d.value);
alert(html);
document.getElementById('<%= h1.ClientID %>').value = html;
var h = document.getElementById('<%= h1.ClientID %>');
alert(h.value);
})();
</script>
我遇到的问题是我有一个 asp.net 服务器端按钮,单击该按钮时我尝试执行此操作:
Label1.Text = h1.Value;
那就是将隐藏字段中的值存储到标签中,但这不起作用。当我在其中放置一个断点时,它显示h1
为空""
....所以我不确定是什么事件或如何执行此操作,以便当我对我的 textarea 进行更改时wmd_input
,我应该能够在我的服务器端看到这些更改代码...
这是我的整个 asp.net 表单:
<html>
<head>
<title>PageDown Demo Page</title>
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<script type="text/javascript" src="js/Markdown.Converter.js"></script>
<script type="text/javascript" src="js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="js/Markdown.Editor.js"></script>
</head>
<body>
<form id="myForm" runat="server">
<div class="wmd-panel">
<div id="wmd-button-bar"></div>
<textarea cols="5" rows="5" id="wmd_input" class="wmd-input" runat="server"></textarea>
<div id="wmd_preview" class="wmd-panel wmd-preview" runat="server"></div>
</div>
<asp:button id="Button1" runat="server" Text="Set" onclick="Button1_Click"></asp:button>
<asp:button id="Button2" runat="server" Text="Get" onclick="Button2_Click"></asp:button><asp:label id="Label1" runat="server">Label</asp:label>
<asp:HiddenField ID="h1" runat="server" EnableViewState="true" />
<script type="text/javascript">
(function () {
var converter1 = Markdown.getSanitizingConverter();
var editor1 = new Markdown.Editor(converter1);
editor1.run();
var d = document.getElementById("wmd_input");
var html = converter1.makeHtml(d.value);
alert(html);
document.getElementById('<%= h1.ClientID %>').value = html;
alert(document.getElementById('<%= h1.ClientID %>').value);
})();
</script>
</form>
</body>
</html>