如何用jQuery清空输入值? [英] How do I empty an input value with jQuery?

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

问题描述

我正在尝试使用可以选择多个图像的图像进行模式对话。我需要从输入中获取值然后清空它,但是我无法清空输入。我尝试过 .val('') .val(null),但都不适合我。



以下是完整的代码:

  $(#hdselect)。 click(function(){
$(。modal)。html();

$ .post('mediaservice.php',{hd:'ok',images :$(#hdimages)。val()},function(data){
$(。modal)。append(data);
});
$( ('
'modal':true,
'title':点击图片选择,
'width':960,
'height ':600,
'resizable':false,
'show':{effect:'drop',direction:up},
'buttons':{Ok:function (){
var hd = Array();
var hdval = $(#hdimages)。val();
$(#hdimages)。attr('value' ,'');
$(input [name ='hd []']:checked)。each(function(){
hd.push($(this).val());
});
if(hdval!=''){
hdval = hdval +,+ hd;
} else {
hdval = hd;
}
$(#hdimages)。val(hdval);
var images = $(#hdimages)。val();
$ .post('mediaservice.php',{getHd:images},function(data){
$(#imgthumbBase)。append(data);
});
$(this).dialog(close);
}
}
});
});

这个想法是,用户点击一个按钮并打开一个模态对话框,其中包含多个图像和复选框。在这一点上,我需要从输入中获取值,然后将其清除。 您可以试试:

  $('input.class')。removeAttr('value'); 
$('#inputID')。removeAttr('value');


I’m trying to make a modal dialog with images where you can select multiple images. I need to get values from an input and then to empty it, but I cannot empty the input. I tried .val('') and .val(null), but neither worked for me.

Here is the full code:

$("#hdselect").click(function(){
        $(".modal").html("");

        $.post('mediaservice.php',{hd:'ok',images:$("#hdimages").val()},function(data){
            $(".modal").append(data);
        });
        $(".modal").dialog({
            'modal':true,
            'title':"Click the image to select",
            'width':960,
            'height':600,
            'resizable':false,
            'show': {effect: 'drop', direction: "up"},
            'buttons': {"Ok": function() {  
                    var hd=Array();
                    var hdval=$("#hdimages").val();
                    $("#hdimages").attr('value',' ');
                    $("input[name='hd[]']:checked").each(function(){
                        hd.push($(this).val());
                    });
                    if(hdval!=''){
                        hdval=hdval+","+hd;
                    }else{
                        hdval=hd;
                    }                        
                    $("#hdimages").val(hdval);
                    var images=$("#hdimages").val();
                    $.post('mediaservice.php',{getHd:images},function(data){
                        $("#imgthumbBase").append(data);
                    });
                    $(this).dialog("close");
                }
            }
        });
    });

The idea is that the user clicks a button and a modal dialog opens with multiple images and checkboxes. At this point I need to get the values from an input, and then clear it.

解决方案

You could try:

$('input.class').removeAttr('value');
$('#inputID').removeAttr('value');

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

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