看起来很简单,但没有办法实现你的要求。
考虑一下:
document.getElementById('myform').addEventListener('submit', function(e) {
e.preventDefault();
console.log(document.getElementById('sometext').value);
console.log('form submitted');
});
document.getElementById('notasubmitbutton').addEventListener('click', function(e) {
console.log(document.getElementById('sometext').value);
});
<form id="myform">
<input type="text" id="sometext">
<input type="submit">
<button id="notasubmitbutton" type="button">Submit 2</button>
</form>
有定期提交按钮会触发提交事件。然后还有另一个按钮,它将收集表单中的所有数据,但不会以传统意义提交。
绝对没有办法可以预见所有可能的方式有人可以建立自己的形式,你问那么什么不能做。
我不能做你的建议,因为它在许多不同的页面上作为内容脚本运行,所以我没有元素的ID。 –
@WaywardSemicolon这不是一个建议,而是一个例子来说明为什么不可能实现你想要做的事情。 – Schlaus