我在我的论坛上进行引用功能。
当用户点击Quote
链接时,我想将此帖内容添加到文本框(txtPost) - 内容不是问题(我试过alert(content)
,它工作正常)。
但文本框中的文本不刷新 - alert(txtPost.value)
显示一些添加的内容等,但文本框仍然是空的。为什么?如何解决它?通过javascript将文本添加到文本框中
帖子:
<asp:HyperLink ID="quotebutton" CssClass="quotebutton" OnClick="javascript:addQuote('somecontent');" runat="server">Quote</asp:HyperLink>
文本框代码:
<nforum:Emoticons ID="emoticonInclude" runat="server" />
<div style="width: 604px; margin-left: 198px;">
<asp:TextBox ID="txtPost" runat="server" TextMode="MultiLine" Rows="14" Width="600"
ClientIDMode="Static"></asp:TextBox>
</div>
JavaScript函数:
function addQuote(content) {
var txtPost = document.getElementById("txtPost");
alert(content);
txtPost.value = txtPost.value + content;
alert(txtPost.value);
}
信息!编辑
我正在使用tinyMCE编辑器。仍然不刷新内容,而tinyMCE连接到此文本框。怎么做?
<script type="text/javascript">
tinyMCE.init({
// General options
mode: "exact",
elements: "txtPost",
theme: "advanced",
plugins: "insertcode",
// Theme options
theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,formatselect,|,bullist,numlist,|,link,unlink,insertcode",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "center",
theme_advanced_resizing: true,
remove_linebreaks: false,
relative_urls: false,
content_css: "/css/nforumeditor.css"
});
</script>
问题解决了
对于tinyMCE-
function addQuote(content) {
tinyMCE.execCommand('mceInsertContent', false, content);
return false;
}
阿迪尔和你们之间的服务器控件,你已经找到了解。您可以将Adil的解决方案添加到您的答案中,也可以将其添加到您的答案中,并且您中的任何一个都可以获得+1。 :) – Bazzz 2013-03-04 09:45:55