猿问

js 这个为啥不判断 直接跳转了页面

慕粉3475506
浏览 1805回答 3
3回答

stone310

这里判断逻辑有问题,filename!=null的意思是只要filename不为null的情况下;而如果未选择未见filename也是不为null,只是为空,因此要判断它的布尔值即可,if(filename){...};这样当未选择时,alert便会执行;另外,防止跳转首先在函数内写上return false;然后在<input>标签上这么写 onclick="return photo()";如:<input type="submit" onclick="return photo()"/> function photo() {     if (1 > 0) {         return false;     } }题外话:像这种判断要放后端去做的,前端做被人随便改

慕妹5461943

MVMCSBYUXHDAWEVRBKNEUKZWOPAKGJKAKCFVIDHYHWLORIRAGHYURCQGIFIYGAKNJAXNDNDMAQGJTWTDTJTCCKHXHEOXFWFOQLIZPSBFVQAXVBLGHVBEVXDEKZCCJTAUURJXAFISRBPZZDWDFVFMFTQJTIYNZBIOSFLVGXQNRQNKILOILGNKSDDRFYEISPOLGSXNURRHNYERWRYIJAKHHBBRLARXHJAUEBHEJSGZUUFZCDTCFFZTDEXLFWCMAHOCXBFGJUOHGGGTVFPTDYLFVSWGWXVSTXPSJSQAAXHJNMTWEVADIISKUILKZEOATUKEOZMDFPRLDTFBFTQNRKLCFCNEBFVTMVBTASVJFIZWJYSSAWWXAYFITZBVPCKLUIAXHKUZQCDNOSFTSSUEZSJQGULLBMFQEMGYVZPTMVVSTDJKXLVPJSGRLLLSVANHDCSUEFPGZFSFAWKXFFWWTHVROAIVFYHMGBYFHZHZNHEFFJPDLCMDANVHHBLFQPDOCUECZTNHOGUOIMMFICOBQZPBPIMAQYBIZGGUYYVCECJCOISVMCKYBGWFJIYWPGXAUKXEYYVTOCZVIGXURKRRAKIICUHCKUYSEVPPFGXBONHZRFFKPOJCWBJURLJQGOLFCNASSGGHKSMWVOYKURETQHLIJICNXZHPMXHFJYUKSQVPTJKEUFWUOOBPTQHEGCWDGCJPWKPPDTTEFFWZMRIQCGDBIBEFPJXUUVGZDBSZJICVGWMASSUXUMDEKTDQAUFWJRVTLEWOVJHEVXNEZZQRJUHEVQFFTSQNEEBYBBRIASCJDUKHOQYCQJTTWNIMNRZTVKKOEBQRRWRLIRBSSQBCISMDYXRBPGXASHVZDWWXWSMZKHISEUVIZGGGQRZSZYXREYBYOWGXWLVWWZKLPWHYBRFZDDDRESPCQKVOPPMDHZXBFLXEEPMJGDBBHICKAKREVLOC

hulukid

停止的话需要写“return”

慕莱坞9220042

你好,要return false; 不然还是会执行下去,或者是判断的不对,可能是空字符串,再判断下空字符串,可以弹出filename看看值。可追问,望采纳!
随时随地看视频慕课网APP

相关分类

Java
JavaScript
我要回答