是否可以使用javascript在我的确认框中触发按钮类型"submit"
?我想触发"OK"
选项上的提交按钮。我想删除HTML表单中的<button type = "submit" class = "btn btn-primary">Okay!</button>
。我只是想在"OK"
选项下触发它可能吗?
的Javascript
<script>
function showApprove()
{
value = confirm("Approve this document?");
if (value == true)
{
// I WANTED TO TRIGGER HERE :)
}
else
{
}
}
function showReject()
{
value = confirm("Reject this document?");
if (value == true)
{
}
else
{
}
}
</script>
查看
<input type="hidden" name = "id" value = "{{$list->id}}">
<div class = "radio">
<label><input type = "radio" onclick = "showApprove()" name = "status" id = "approve" value="1"> Approve</label>
</div>
<div class = "radio">
<label><input type = "radio" onclick = "showReject()" name = "status" id = "reject" value="0"> Reject</label>
</div>
<button type = "submit" class = "btn btn-primary">Okay!</button>
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">
所以我的视图在我的HTML中看起来没有按钮了。我只是想在我的确认框中触发它。
答案 0 :(得分:0)
调用表单元素上的submit()
方法以触发提交事件
document.querySelector(".form-line").submit();
答案 1 :(得分:0)
调用提交函数,在表单中添加一个id =&#34; myForm&#34;
document.getElementById("myForm").submit();
答案 2 :(得分:0)
答案 3 :(得分:0)
.submit()答案是正确的,他们将提交表格,但如果你需要点击按钮而不是因为某些原因使用javascript提交表格(比如,你需要按钮值或其他东西)请使用以下代码
<强> HTML 强>
access_modificatior variable_name: type = default_value
<强> JAVASCRIPT 强>
<button type="submit" class="btn btn-primary" id="okbutton" >Okay!</button>
答案 4 :(得分:0)
更改:
<button type = "submit" class = "btn btn-primary">Okay!</button>
致:
<button type = "button" class = "btn btn-primary">Okay!</button>
然后:
<script>
function showApprove()
{
if(confirm("Approve this document?"))
{
document.getElementById("myForm").submit();
}
else
{
return false;
}
}
</script>