我想让用户双击我网页上的li元素,然后将li文本添加到下面的textarea中。jQuery中的append()函数
用户可以双击多个li项目。每次发生这种情况,新项目都会附加到textarea中列表的后面。
我在textarea中有一些默认文本:“双击手写插入的电影名称。”
因此,下面的HTML代码:
<!-- there is a list before this which I have not included -->
<div id="chosen">
<form action="process.php?stage=4" method="post">
<textarea name="g" row="5">Double click on movie name in list above to insert.</textarea>
<input type="submit" />
</form>
</div>
和jQuery:
$(document).ready (function(){
$('li').bind('dblclick', function(){ //#accordion
var text = $(this).html() + "; ";
$("textarea").append(text);
});
});
的代码在正常circumtances绝对有效,但停止时,我在textarea的点击修改其内容的工作。这是为什么?即使我触摸了textarea的内容,是否有办法让代码正常工作?
(2) 另一方面,为什么下面的代码不起作用?我在发现append()方法之前尝试了这一点。它与$(this)范围有关吗?
$(document).ready (function(){
$('li').bind('dblclick', function(){ //#accordion
var text = $(this).html() + "; ";
$("textarea").html(function() { //.chosen
var currenthtml = $(this).html(); // retrieve the current HTML first
currenthtml += text;
return currenthtml; });
});
});
(3)另外,我怎么程序功能允许,如果用户已经双击锂元素,其包含到文本区域,撤销,列入?有没有一种方法可以让我做与append()相反的方法?
只询问一个问题职位 – 2013-05-02 12:06:48