<div> <input type="file" id="iid"><span></span> </div> <script> var ttt = document.getElementById("iid"); ttt.onchange = function () { var text = this.value; var str = text.substr(text.lastIndexOf(".")).toUpperCase(); //最后一个点开始截取字符串,并转化为大写; if (str == ".JPG"|| str == ".PNG") { this.nextSibling.innerHTML = "格式正确"; }else{ this.nextSibling.innerHTML = "格式错误"; } }; </script>
选择文件格式判断
最新推荐文章于 2024-09-09 17:36:30 发布