0

フォーラムで引用機能を作成しています。
ユーザーが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;
}
4

3 に答える 3

1

JavaScript でサーバー コントロールを使用するには、サーバー コントロールの ClientID を呼び出す/取得する必要があります。

html

<asp:HyperLink ID="quotebutton" CssClass="quotebutton" OnClick="javascript:return addQuote('somecontent');" runat="server">Quote</asp:HyperLink>

JavaScript

function addQuote(content) {
var txtPost = document.getElementById("<%= txtPost.ClientID %>");
txtPost.value = txtPost.value + content;
return false;
}
于 2013-03-04T09:32:45.423 に答える
0

Tou はreturn false;関数内で postback を防止する必要があります。

于 2013-03-04T09:31:41.667 に答える
0
<asp:TextBox ID="txtPost" runat="server"></asp:TextBox>
<asp:HyperLink ID="quotebutton" runat="server" onclick="javascript:addQuote('some content');">Quote</asp:HyperLink>

function addQuote(content) {
        var txtPost = document.getElementById('<%= txtPost.ClientID %>');
        txtPost.value = txtPost.value + content;
    }
于 2013-03-04T09:56:07.353 に答える