Why are the buttons of the type submit?
Th开发者_如何学编程is is the html:
<button>Static</button>
<form>
<span id="test"> </span>
</form>
This is the jQuery - runs in the document.ready:
$('#test').append('<button>Dynamic</button>');
$('button').live('click', function(){
alert($(this).attr('type'));
});
//even this one:
alert($('<button>test</button>').attr('type'));
The it alerts it says the 'type' is 'submit', but I haven't specified a type. How come? At least IE and Chrome are consequent in giving it the type "submit". But I don't even have a form, so it seems weird to make it a submit-button.
The default value for the type attribute for <button>
elements is defined as 'submit' in the specification.
submit: Creates a submit button. This is the default value.
http://www.w3.org/TR/html4/interact/forms.html#h-17.5
精彩评论