将文本插入 Markitup 文本编辑器

发布于 2024-10-09 13:02:10 字数 643 浏览 7 评论 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 中我看到但实际上文本已经存在

alt text

有什么想法如何实现正确的文本插入吗?

I've wrote a code

$(".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>');
});

After click text insert in textarea. But if user insert or write some text into textarea or delete text and after click on quote link, text not displaying in textarea but in Firebug I've see but actually text already exists

alt text

Any ideas how I do implement a proper text insertion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

子栖 2024-10-16 13:02:11

我修改了 markitup 附带的示例(查看 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">
<h1>Welcome on markItUp!</h1>

<p><strong>markItUp!</strong> 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.</p>
</textarea>
</p>
</body>
</html>

您在文本区域中设置光标位置,选择文本并单击链接“...添加内容...”。脚本只是将您选择的文本放入光标位置的文本区域中。抱歉使用 document.getSelection() - 在 jQuery 中没有找到任何类似的实用函数 =)

I've modified example, which comes with markitup (take a look over index.html in the Markitup! archive) and here what we've got:

<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">
<h1>Welcome on markItUp!</h1>

<p><strong>markItUp!</strong> 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.</p>
</textarea>
</p>
</body>
</html>

You set cursor position in the textarea, select text and click link "...add content...". Script simply puts text you've selected into textarea in the cursor position. Sorry for using document.getSelection() - haven't found any similar utility function in jQuery =)

谁人与我共长歌 2024-10-16 13:02:11

这取决于您使用的编辑器。
对于 markItUp 你可以这些;

$.markItUp({ name:"YourWord", openWith:"[b]", closeWith:"[/b]" })
$.markItUp({ replaceWith: "yourCustomEntry" });

it depends on which editor you use.
for markItUp you can theese;

$.markItUp({ name:"YourWord", openWith:"[b]", closeWith:"[/b]" })
$.markItUp({ replaceWith: "yourCustomEntry" });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文