0

コードを書きました

$(".ka_opinions_quote a").click(function(){
    var quoted_text = $(this).parents("div.o_opinion").find(".ka_opinion_txt").text();
    var cite_uri = $(this).parents("div.o_opinion").prev().find("a").attr("href");
    var curr_text = $(".editor").text();

    $(".editor").text(curr_text+'<quote cite="<?php echo mb_substr(JURI::base(), 0, -1); ?>'+cite_uri+'">'+quoted_text+'</quote>');
});

クリックした後、テキストエリアにテキストを挿入します。しかし、ユーザーがテキストエリアにテキストを挿入または書き込むか、テキストを削除し、引用リンクをクリックした後、テキストエリアにテキストが表示されませんが、Firebug には表示されますが、実際にはテキストが既に存在します

代替テキスト

適切なテキスト挿入を実装する方法はありますか?

4

2 に答える 2

1

マークアップに付属する例を修正しました ( Markitup! アーカイブのindex.htmlを参照してください)。

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="markitup/jquery.markitup.js"></script>
<script type="text/javascript" src="markitup/sets/default/set.js"></script>
<link rel="stylesheet" type="text/css" href="markitup/skins/markitup/style.css" />
<link rel="stylesheet" type="text/css" href="markitup/sets/default/style.css" />
</head>
<body>
<script type="text/javascript">
$(document).ready(function()    {
    $('#markItUp').markItUp(mySettings);
    $('.add').click(function() {
        $.markItUp( {   openWith:'<opening tag>',
                        closeWith:'<\/closing tag>',
                        placeHolder:document.getSelection()
                    }
                );
        return false;
    });
});
</script>
<p>Click <a href="#" class="add">this link to insert content</a> from anywhere in the page</p>
<p>
<textarea id="markItUp" cols="80" rows="20">
&lt;h1&gt;Welcome on markItUp!&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;markItUp!&lt;/strong&gt; is a JavaScript plugin built on the jQuery library. It allows you to turn any textarea into a markup editor. Html, Textile, Wiki Syntax, Markdown, BBcode or even your own markup system can be easily implemented.&lt;/p&gt;
</textarea>
</p>
</body>
</html>

テキストエリアにカーソル位置を設定し、テキストを選択して、リンク「...コンテンツを追加...」をクリックします。スクリプトは、選択したテキストをテキストエリアのカーソル位置に配置するだけです。document.getSelection()を使用して申し訳ありません- jQuery で同様のユーティリティ関数が見つかりません =)

于 2010-12-24T14:21:50.117 に答える
0

使用するエディターによって異なります。markItUp の場合、次のことができます。

$.markItUp({ name:"YourWord", openWith:"[b]", closeWith:"[/b]" })
$.markItUp({ replaceWith: "yourCustomEntry" });
于 2010-12-24T16:27:39.580 に答える