[英]insert text into an sceditor textarea from a div?
Hi all I am very new to javascript and jquery so bear with me, I am trying to make a multi-quote system for my sites comments system. 大家好,我对javascript和jquery还是很陌生,所以请允许我,我正在尝试为我的站点评论系统创建一个多引用系统。 SCEditor is this btw: http://www.sceditor.com/
SCEditor是这个顺便说一句: http : //www.sceditor.com/
I have this code 我有这个代码
<script>
function insert_quote(quote_id)
{
var text = Document.getElementById(quote_id).innerHTML;
$('textarea').sceditor('instance').insert(text);
}
</script>
And this: 和这个:
<td valign="top">
<div id="{:comment_id}" class="forumpost">{:text}</div><br />
<a onclick="insert_quote({:comment_id});">Multi Quote Test</a>
</td>
Where {:comment_id} would be the id of the comment from the database. 其中{:comment_id}是数据库中评论的ID。
It doesn't work since i'm obviously doing something stupidly wrong, can someone help? 由于我明显做错了某件事,所以它不起作用,有人可以帮忙吗?
First you didn't put quote to (quote_id)
and document
have not uppercase so it is why it doesn't work. 首先,您没有在
(quote_id)
引号,并且document
没有大写,所以这就是为什么它不起作用。 But it would be preferable do to all by jQuery and remove the "onclick" attribute like this. 但是最好使用jQuery并像这样删除“ onclick”属性。
JS JS
$('.comment').on('click', function() {
var text = $(this).prev('.forumpost').text();
$('textarea').sceditor('instance').insert(text);
});
HTML 的HTML
<td valign="top">
<div id="{:comment_id}" class="forumpost">{:text}</div><br />
<a class="comment">Multi Quote Test</a>
</td>
EDIT 编辑
Here's a jsFiddle to see it in action. 这是一个jsFiddle ,可以实际使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.