关于为什么有些<a>和<input>标签中的onclick方法会有return,如<a class = '' onclick = upload();return>

关于为什么有些<a>和<input>标签中的onclick方法会有return,如<a class = '' onclick = "upload();return;" ></a>


今天刚好看到代码中有上传事件;其中有个点击附加上传的方法,但是这个upload()方法后面还有个return,我查了下,有些写的是return false;意思是这个onclick方法中已经有提交了,如果不写return 就会有两次提交,因为在最后的form标签还会提交一次。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="./CSS/index.css"> <script type="text/javascript" src="./js/jquery-3.3.1.js"></script> <title>Document</title> </head> <body> <div class="divclass"> <button onclick="getLogIn()">log in</button> <hr> <input type="file" id="uploadFile" name="uploadFile" /> <button onclick="addFile()" type="submit">提交</button> <hr> <input type="text" id="downloadfilename"> <button onclick="downloadFile()" target="new target">下载</button> </div> </body> <!-- http://127.0.0.1:8082/localTest/upload --> <!-- http://127.0.0.1:8082/localTest/testDownload --> <script> function getLogIn() { window.location.href = "./pages/login.html"; } function downloadFile() { var filename = document.getElementById("downloadfilename").value; //window.open("http://127.0.0.1:8082/localTest/testDownload?filename=" + encodeURI(filename)); window.open("http://127.0.0.1:8088/api/DownloadByCustomer?filename=" + encodeURI(filename)); } function addFile() { var formData = new FormData(); formData.append("file1", document.getElementById('uploadFile').files[0]); $.ajax({ url: 'http://127.0.0.1:8088/admApi/admUpload', type: 'POST', data: formData, // 上传formdata封装的数据包 //dataType: 'JSON', timeout: 10000, cache: false, // 不缓存 processData: false, // jQuery不要去处理发送的数据 contentType: false, // jQuery不要去设置Content-Type请求头 success: function (res) { console.log(res) console.log("上传成功"); return alert("上传成功"); }, error: function (sd) { console.log(sd) console.log("上传失败"); return alert("上传失败"); } }); }; </script> </html>
最新发布
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值