如何使用jQuery清空文本区域中的消息? [英] How to empty the message in a text area with jquery?

查看:76
本文介绍了如何使用jQuery清空文本区域中的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-更新-

我想在回调的文本区域中清空消息.

I want to empty message in a textarea in callback.

有人可以告诉我如何清空吗?

Can anyone tell me how to empty it please?

我尝试了$(#message").empty(),但它没有将其清空.

I tried $("#message").empty(), but it does not empty it.

谢谢.

 <form method="post" id="form" action="index.php/admin/messages/insertShoutBox">

    <input name="user" id="nick" value="admin" type="hidden">
    <p class="messagelabel"><label class="messagelabel">Message</label>
    <textarea id="message" name="message" rows="2" cols="40"></textarea>
    <input disabled="disabled" id="send" value="Sending..." type="submit"></p>

</form>

完整代码

 $("#form").submit(function(){
    if(checkForm()){
        var nick = inputUser.attr("value");
        var message = inputMessage.attr("value");
        //we deactivate submit button while sending
        $("#send").attr({ disabled:true, value:"Sending..." });
        $("#send").blur();
        //send the post to shoutbox.php
        $.ajax({
            type: "POST", 
            url: "index.php/admin/dashboard/insertShoutBox", 
            data: $('#form').serialize(),
            complete: function(data){
                messageList.html(data.responseText);
                updateShoutbox();
                 $('#message').val('').empty();
                //reactivate the send button
                $("#send").attr({ disabled:false, value:"SUBMIT !" });
            }
         });
    }
    else alert("Please fill all fields!");
    //we prevent the refresh of the page after submitting the form
    return false;
});

推荐答案

$('#message').val('');

说明(来自@BalusC):
textarea是具有值的input元素.您实际上想清空"该值.因此,对于所有其他input元素(inputselecttextarea),您需要使用element.val('');.

Explanation (from @BalusC):
textarea is an input element with a value. You actually want to "empty" the value. So as for every other input element (input, select, textarea) you need to use element.val('');.

另请参见文档

这篇关于如何使用jQuery清空文本区域中的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆