相关文章
更多最近更新
更多我一点onclick为什么总是提交表单
2019-03-25 13:39|来源: 网路
下面是一个表单,有一个onclick按钮,点击后上面文本框的内容被添加到下面的文本域中,并可以一直添加,然后点击submit后提交到另一个页面。但是,在Ie9或者火狐浏览器中我一点onclick为什么总是提交表单,在搜狗,360浏览器中并未出现这样的状况。想问是不是浏览器的兼容问题,该如何解决。
<form action="abc.jsp" method="get" >
<input id = "input" size="30" maxlength="100" onMouseOver="this.focus()" onFocus="this.select()" />
<button onclick="document.getElementById('textarea').value+=
document.getElementById('input').value+' '" >add</button>
</p>
<p>
<label for="textarea"></label>
<textarea name="name" id="textarea" cols="40" rows="5" readonly="true"></textarea>
<input type="submit" id="button2" value="submit" />
<input type="reset" id="button" value="reset" />
</p>
</form>
<form action="abc.jsp" method="get" >
<input id = "input" size="30" maxlength="100" onMouseOver="this.focus()" onFocus="this.select()" />
<button onclick="document.getElementById('textarea').value+=
document.getElementById('input').value+' '" >add</button>
</p>
<p>
<label for="textarea"></label>
<textarea name="name" id="textarea" cols="40" rows="5" readonly="true"></textarea>
<input type="submit" id="button2" value="submit" />
<input type="reset" id="button" value="reset" />
</p>
</form>
相关问答
更多-
你有一个输入名称=“提交”,这是导致问题。 此外,您的HTML中没有按钮。 You have a input name="submit", this is causing the problem. Also, there is no button in your html.
-
如何在提交按钮onclick活动中取消表单提交?(How do I cancel form submission in submit button onclick event?)[2022-03-07]
你最好做... 如果isValidForm()返回false ,则表单不会提交。 你也应该从内联移动你的事件处理程序。 document.getElementById('my-form').onsubmit = function() { return false; }; You are better off doing... If ... -
您使用图像作为输入类型。输入类型没有图像类型。 而不是使用type =“button”。 改为使用validate方法调用提交表单。 You used image as input type.input type does not have image type. instead of use type="button". call submit form in validate method instead.
-
你的onclick语法是错误的,但在元素上添加onclick属性是一种过时的做事方式。 您可能想要处理change事件而不是click ,因为click后选择了radiobutton,所以如果您立即提交表单,则可能尚未选择radiobutton(我不确定,我必须实验,但change可能更加万无一失。 $(document).ready(function() { $('input[type=radio]').change(function(event) { //the rest of ...
-
由于没有答案,这是我对你的看法: - 阿贾克斯 因为您正在使用Rails UJS Ajax驱动程序 ,所以您需要捕获来自远程服务器的响应,从而允许您相应地填充表单上的feedback元素: #app/assets/javascripts/application.js $(document).on("ajax:success", "#your_form", function() { $("#feedback_module").html("Thanks for your feedback"); }); ...
-
只需删除锚标记即可。 它应该是这样的:Just remove the anchor tag. This is how it should look like :假定HTML表单中的按钮用于提交表单。 更改按钮以输入type =“button”,这应该修复它。 或者,将button =“button”添加到按钮元素。 A button in an HTML form is assumed to be used to submit the form. Change button to input type="button" and that should fix it. Alternatively, add type="button" to the button el ...根据replaceWith()文档: .replaceWith()方法从DOM中删除内容,并通过一次调用在其位置插入新内容。 根据remove()文档删除元素时: 除了元素本身之外,还删除了与元素关联的所有绑定事件和jQuery数据。 我假设这就是提交没有执行的原因。 如果您希望表单仍然提交,则可以在替换元素后手动触发提交。 演示 - 替换按钮元素时提交表单 为了便于阅读,为了演示,我已将click事件的绑定移动到脚本而不是元素的内联。 我还在多个表单的情况下添加了一个id,如果你只有一个表单就不需要了,因 ...
如何防止表单提交触发`按钮:first.onclick()`?(How to prevent form submit from triggering `button:first.onclick()`?)[2023-06-10]
-snip- 编辑理想情况下,我想暂停提交,直到表单被验证。 这就是jQuery Validate插件已经在做的事情。 你的代码...... $('#button1').on('click', function() { $("#issueform").valid(); //everything works upto here if($validator.noOfInvalids()===0){ //this code doesn't work $('#myModal').moda ...