我遇到了我的提交代码问题。我正在使用第三方公司的计算器,并且在提交表单时我试图触发一些JavaScript。警报将启动,但如果我将返回设置为false,表单仍会提交。Javascript onSubmit not returned false
下面是代码,我在我自己的环境中工作线: document.getElementsByTagName("Form")[3].onsubmit = function() { alert('Test'); return false; };
我已经在这里建立了一个副本: (对于什么都理它不会加载在片段中,我复制相同的代码到我的服务器,它工作正常,所以这里是它在行动。Page)
function myFunction() {
document.getElementsByTagName("Form")[0].onsubmit = function() { alert('Test'); return false; };
}
<button onclick="myFunction()">Wait for script to load then press this button to add the onsubmit, then you can press calculate</button>
<script src="https://calculators.symmetry.com/widget/js/salary.js?key=RHA0Slc2ZjEydjNkR0Y2eTEvOUxpZz09"></script>
I H还没有想出如何为脚本执行onload检测,所以这就是为什么你必须等待脚本加载然后按下按钮才能插入javascript。
感谢您的任何帮助。
那么如何加载窗体,你不能附加它没有onclick? – epascarello
@epascarello,公司提供的脚本构建计算器。所以,如果我在页面加载时运行javascript,它将不会找到表单,因为它尚未构建。这就是为什么我需要一个脚本的onload,我还没有建立。 –