【问题标题】:Why are the buttons of the type submit?为什么是提交类型的按钮?
【发布时间】:2023-03-12 06:55:01
【问题描述】:

这是html:

<button>Static</button>
<form>
<span id="test"> </span>
</form>

这是 jQuery - 在 document.ready 中运行:

    $('#test').append('<button>Dynamic</button>');

    $('button').live('click', function(){
       alert($(this).attr('type')); 
    });

    //even this one:
    alert($('<button>test</button>').attr('type'));

它提醒它说“类型”是“提交”,但我没有指定类型。怎么会?至少 IE 和 Chrome 会因此给它“提交”类型。但是我什至没有表单,所以将其设置为提交按钮似乎很奇怪。

【问题讨论】:

    标签: javascript jquery html dom button


    【解决方案1】:

    &lt;button&gt; 元素的 type 属性的默认值在规范中定义为“提交”。

    submit:创建一个提交按钮。这是默认值。

    http://www.w3.org/TR/html4/interact/forms.html#h-17.5

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    • 2023-03-22
    • 2020-05-28
    • 1970-01-01
    • 2016-10-10
    相关资源
    最近更新 更多