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");
                }
            }
        });
    });

这个 idea 是,用户点击一个按钮,就会打开一个模式对话框,其中有多个图像和复选框.此时,我需要从输入中获取值,然后清除它.

推荐答案

You could try:

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

Jquery相关问答推荐

如何使用 JQuery 将详细信息中的项目包装在容器中?

Ajax 替换而不是追加

如何使用 aria-expanded="true" 更改 CSS 属性

jQuery在点击函数后获取
  • 元素的id/value
  • jQuery - 向下滚动时缩小的粘性标题

    将变量传递给jQuery AJAX成功回调中的函数

    jQuery Mobile:动态添加内容的标记增强

    Facebook 风格的 JQuery 自动完成插件

    jQuery/JavaScript 碰撞检测

    基于垂直滚动的jquery添加/删除类?

    jQuery .get 错误响应函数?

    jQuery切换文本?

    jQuery中的Grep与过滤器?

    如何在 jQuery 中 Select this中的元素?

    带有 LIKE 的 Spring JPA @Query

    如何使用 bootstrap 中的 selectpicker 插件在 Select 时设置选定值

    只绑定一次事件

    Twitter Bootstrap 中的树

    jquery $(window).height() 正在返回文档高度

    小于 10 给数字加 0