【问题标题】:IE incorrectly treats HTML <button> as submit buttonIE 错误地将 HTML <button> 视为提交按钮
【发布时间】:2011-12-21 05:14:11
【问题描述】:

我有两个 HTML 按钮;一个提交表单,一个关闭容器对话框。关闭它的按钮没有type 属性:

<button type="submit">Submit</button>
<button class="closeDialog">Close</button>

JavaScript如下:

$(".closeDialog").live("click", function(event) {
  event.preventDefault();
  $(this).parents(".dialog").dialog("close");
});

$("form.myClass").live("submit", function(event) {
  event.preventDefault();
  // submits the form here . . .
});

所有这些都适用于除 IE 之外的所有浏览器。在 IE 中,当单击“关闭”按钮时,上面的两个 JavaScript 事件都会执行,但只有 .closeDialog 事件处理程序应该执行。

IE 似乎将元素视为提交按钮,而不管其type 属性如何。

如何解决 IE 中的这种误解?

【问题讨论】:

  • 也许添加您尝试过的 IE 版本/模式? (不确定它是否重要)
  • 什么版本的IE?另外,也许试试 ?
  • 始终将类型按钮设置为按钮、重置或提交,因为每个浏览器可能有不同的处理方式...设置渲染默认值。此外,建议使用 type="button" 而不是 "button" 的输入,因为它的行为在表单中更容易预测。

标签: html css internet-explorer browser cross-browser


【解决方案1】:

第二个,试试:&lt;button type="button"&gt;

【讨论】:

  • 显然,“提交”是默认类型仅在 IE 中
【解决方案2】:

试试:

<input type='button' />

这在大多数情况下都适用于 IE。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    相关资源
    最近更新 更多