

点击取消后还是会把表单提交上去
为咋的
表单html
<form role="search" method="POST">
<label for="name">选择更新的项目</label>
<select class="form-control" name="selectid" id="optionvalue">
{% for key,value in prodict.items() %}
<option value ="{{ key }}" >
{{ value }}
</option>
{% endfor %}
</select>
<p class="form-group" style="margin-top: 40px">
{{ versionform.hidden_tag() }}
{{ render_field(versionform.version,class="form-control",placeholder="Version Num",id="versionnum") }}
</p>
<button type="button" class="btn btn-default" onsubmit="return test();">Submit</button>
</form>
js内容
function test(){
var optionNum = document.getElementById("optionvalue").selectedIndex;
var optionValue = document.getElementById("optionvalue").options;
var options = optionValue[optionNum].text
var versionNum = document.getElementById("versionnum").value;
console.log(options);
console.log(versionNum);
if (confirm("更新" + options + "的版本号为:" + versionNum + "?....")){
return false;
}else{
return false;
}
}
=====搞定了====
放错位置了
html内容

js内容

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把 onsubmit="return test();" 放到form上面去而不是放到submit的button试试看!
button标签自带submit
使用
onclick不要用onsubmit為什麼
test()無論如何都 returnfalse?onsubmit="test()"
试试