フォーラムで引用機能を作成しています。
ユーザーがQuote
リンクをクリックすると、この投稿のコンテンツを textbox(txtPost) に追加したい - コンテンツは問題ありません (試してみalert(content)
ましたが、動作します)。
しかし、テキストボックスのテキストは更新されません -alert(txtPost.value)
追加されたコンテンツなどを表示しますが、テキストボックスはまだ空です。なんで?それを解決する方法は?
役職:
<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;
}