开发者

HTML form and Jquery

I have a problem with HTML form and Jquery.

The simplified version looks like this:

HTML:

<form action="" method="post" id="send" name="send">
<textarea name="resp" cols="25" class="resp" rows="3"></textarea>
<input type="submit" value="send" class="fsend" />
</form>

Jquery:

$(document).ready(function() {
$("form#send").submit(function() {
var rs= $('.resp').attr('value');
$.ajax({
type: "POST",
url: "?a=up",
data: "rs="+ rs,
success: function(){
$(".<?=$pid;?>").text('开发者_C百科ok').addClass('pzd');
$(".<?=$td;?>").hide();
}

});
return false;
});
});

The problem that I have with this form and Jquery code is that the ajax post always the same value of texterea. How can I empty or clear the textarea after sending data to PHP file using ajax and than be ready to input new data in textarea?

I tried using document.send.resp.value = ''; , send.resetForm(); $(".resp").val('') and many others, in on out of ajax success function...and without result.

Any help?


I don't get why this doesn't work for you...

$('.resp').val('');

Works fine when I tried it.

See here: http://jsfiddle.net/ryleyb/d7zX6/2/


Here you have a jquery plugin which can handle your ajax requests very easy. http://jquery.malsup.com/form/


Did you try

$(':input','#send')
.val('');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜