Javascript .submit()覆盖必填字段

Edu*_*nco 6 html javascript forms

我有一个表格,希望在发送之前先确认模式。我用JavaScript做到这一点。我打开模态,然后使用.submit()函数,但是它不考虑“必填”字段而发送表格。

这是我使用http://www.w3schools.com/制作的示例:

<!DOCTYPE html>
<html>
<body>

<form id="some" action="demo_form.asp">
  Username: <input type="text" name="usrname" required>
  <input type="submit">
</form>

<p><strong>Note:</strong> The required attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>
<button type="button" onclick="document.getElementById('some').submit();">Send anyway</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是小提琴:http : //jsfiddle.net/fmpk1h1m/

required无论我直接发送表单还是通过JavaScript发送表单,我都希望属性具有相同的效果。

Mig*_*ota 5

触发表单提交按钮点击:

var form = document.getElementById('form');
var submitButton = document.getElementById('submit-button');
var sendButton = document.getElementById('send-button');

sendButton.addEventListener('click', send);

function send(e) {
    submitButton.click();
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/8rwfspbt/1/