我对textarea进行更改后,jQuery追加功能不再起作用 [英] jQuery append function doesn't work again after I made a change on textarea
问题描述
我有1个按钮
<input type="button" id="scrape-button" value="Scrape" />
<textarea id="result" name="result"></textarea>
<textarea id="temp" name="temp" style="display: none;"></textarea>
当我首先单击抓取"按钮时,它会起作用
When I click scrape button first it works
但是当我在textarea上手动填充某些内容然后再次单击刮擦"按钮时,$("#result").append($("#temp").val())
功能将不再起作用.为什么?
But when I fill something manually on textarea then click scrape button again, $("#result").append($("#temp").val())
function doesn't work again. why?
$(document).ready(function(){
$("#scrape-button").click(function(){
var i = 0;
var start = $("#start").val();
var num = $("#num").val();
var pages = $("#pages").val();
$("#result").val("");
load(i, pages, start, num);
});
function load(i, pages, start, num) {
if (i < pages){
url = $("#category").val() + $("#collection").val();
$("#url").text("h" + url);
$("#temp").load("coba.php?url=" + encodeURIComponent(url) + "&start=" + start + "&num=" + num, function(){
if ($("#result").val() != '') $("#result").append("\n");
$("#result").append($("#temp").val());
start = parseInt(start) + parseInt(num);
i++;
$("#current").text(i + " / " + pages);
load(i, pages, start, num);
});
}
}
});
如何使其起作用?
谢谢
推荐答案
在$("#result")
上使用append
不会像您期望的那样追加到textarea
的值上-为此,您需要使用val()
功能.
The use of append
on $("#result")
will not append to the value of the textarea
like you may expect - for that you need to use the val()
function.
因此,要覆盖textarea
的所有内容,请使用:
So instead, to overwrite all the contents of the textarea
, use:
$("#result").val($("#temp").val());
要附加到textarea
的内容,请使用类似于以下内容的
To append to the contents of the textarea
, use something similar to:
var $result = $("#result");
$result.val($result.val() + $("#temp").val());
这篇关于我对textarea进行更改后,jQuery追加功能不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!