4

当在线工作解决方案未选择文件时,我正在尝试禁用提交按钮。它与脚本类型有关吗?

这是我遵循的示例:禁用提交按钮,直到选择要上传的文件

<html>
        <head>

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
            $(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>
4

2 回答 2

2

尝试声明 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>
于 2013-06-04T08:58:33.113 回答
0

将 jQuery 库包含在<head>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
于 2013-06-04T08:59:01.530 回答