加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 如何检查是否使用javascript选择了文件?

发布时间:2020-12-13 22:34:51 所属栏目:PHP教程 来源:网络整理
导读:在 PHP中,这是检查文件是否被选中的方式: $_FILES['item']['size']0 用JavaScript怎么样? 我需要知道,因为我有一个仅在选择文件时才有效的功能. http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-49531485说: value of type DOMString When the type
在 PHP中,这是检查文件是否被选中的方式:
$_FILES['item']['size']>0

用JavaScript怎么样?

我需要知道,因为我有一个仅在选择文件时才有效的功能.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-49531485说:

value of type DOMString
When the type attribute of the element has the value “text”,“file” or “password”,this represents the current contents of the corresponding form control,in an interactive user agent.

<html>
  <head><title>...</title>
    <script type="text/javascript">
      function foo() {
        var f = document.getElementById("f1");
        alert( ""==f.value ? "nothing selected" : "file selected");
      }
    </script>
  </head>
  <body>
    <form>
      <div>
        <input id ="f1" type="file" name="x" />
      </div>
    </form>
    <button onclick="foo()">click</button>
  </body>
</html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读