Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未选择文件时禁用提交按钮_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 未选择文件时禁用提交按钮

Javascript 未选择文件时禁用提交按钮,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我试图禁用提交按钮时,一个文件没有被选中的工作解决方案在线。这与脚本类型有关吗 这是我遵循的示例: $(文件)。准备好了吗( 函数(){ $('input:submit').attr('disabled',true); $('input:file')。更改( 函数(){ if($(this.val()){ $('input:submit').removeAttr('disabled'); } 否则{ $('input:submit').attr('disabled',true); } });

我试图禁用提交按钮时,一个文件没有被选中的工作解决方案在线。这与脚本类型有关吗

这是我遵循的示例:


$(文件)。准备好了吗(
函数(){
$('input:submit').attr('disabled',true);
$('input:file')。更改(
函数(){
if($(this.val()){
$('input:submit').removeAttr('disabled');
}
否则{
$('input:submit').attr('disabled',true);
}
});
});

尝试声明Jquery,因为Jquery不包括在内:

  <html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.0.js"></script>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 


            <script type="text/javascript">
                $(document).ready(
        function(){
            $('input:submit').attr('disabled',true);
            $('input:file').change(
                function(){
                    if ($(this).val()){
                        $('input:submit').removeAttr('disabled'); 
                    }
                    else {
                        $('input:submit').attr('disabled',true);
                    }
                });
        });
            </script>
    </head>

    <body>
       <form action="#" method="post">

                <input type="file" name="fileInput" id="fileInput" />
                <input type="submit" value="submit" disabled />


           </form>
    </body>
    </html>

$(文件)。准备好了吗(
函数(){
$('input:submit').attr('disabled',true);
$('input:file')。更改(
函数(){
if($(this.val()){
$('input:submit').removeAttr('disabled');
}
否则{
$('input:submit').attr('disabled',true);
}
});
});

将jQuery库包括在



您是否包含jQuery库?您的代码运行良好-。这里没有包含jQuery库。但是,当您选择一个文件时,实际发生了什么?您想只在按下按钮或真正选择文件时启用该按钮吗?您好,谢谢您的帮助。我已经编辑了javascript部分。但是,它仍然不起作用。嗨,谢谢你的帮助。我试过编辑src,但仍然不起作用。可能是别的什么吗?但这很奇怪。它在Jsfiddle.net上工作对不起,在我的电脑功能上,你想在提交后做什么??脚本需要连接的Internet才能使用Jquery。否则,请复制、粘贴文字或便笺并保存在pc上,以便在不使用InternetHi的情况下使用,再次感谢。我想做的是在我选择了一个文件后启用按钮。如果未选择任何文件,则应禁用该文件。目前它最初是禁用的,但在选择文件后,它仍然是禁用的。你们想说的是,如果我想使用jquery,我需要连接到internet?对不起,我对这个很陌生。欢迎。。。脚本您好,我已向您发送电子邮件,并将您添加到skype中。你有空的时候告诉我。非常感谢米尔科。
  <html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.0.js"></script>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 


            <script type="text/javascript">
                $(document).ready(
        function(){
            $('input:submit').attr('disabled',true);
            $('input:file').change(
                function(){
                    if ($(this).val()){
                        $('input:submit').removeAttr('disabled'); 
                    }
                    else {
                        $('input:submit').attr('disabled',true);
                    }
                });
        });
            </script>
    </head>

    <body>
       <form action="#" method="post">

                <input type="file" name="fileInput" id="fileInput" />
                <input type="submit" value="submit" disabled />


           </form>
    </body>
    </html>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>