嗨我有以下功能,当我在其中添加OR条件时,其行为会有所不同.
<script>
function checkfield(obj)
{
var full_name = obj.upload_image.value.toLowerCase();
var full_length = parseInt(full_name.length);
var dotAt = parseInt(full_name.lastIndexOf("."));
var ext = full_name.substring((dotAt+1), full_length);
if(ext == "jpg" || ext == "png")
{
//alert("Sorry! allowed file types are .png, .gif, .jpg");
//return false;
console.log("Correct Extention");
}
else{
console.log("Wrong extention");
}
return false;
}
</script>
Run Code Online (Sandbox Code Playgroud)
我在||操作员之前给出了什么,它工作正常,第二个失败.请有人可以选择我做错了什么或者应该怎么做.
你的条件很好,问题可能与价值有关ext.我想console.log或者看一下调试器中的值,它可能不是你认为的那样.

编辑,从评论中,你说文件名是text.PNG."PNG"与"png"不同
| 归档时间: |
|
| 查看次数: |
119 次 |
| 最近记录: |