点击取消后还是会把表单提交上去
为咋的
表单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>
<div class="form-group" style="margin-top: 40px">
{{ versionform.hidden_tag() }}
{{ render_field(versionform.version,class="form-control",placeholder="Version Num",id="versionnum") }}
</div>
<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内容
把 onsubmit="return test();" 放到form上面去而不是放到submit的button试试看!