Why can't I change the type of an input element to submit?

前端 未结 7 1421
盖世英雄少女心
盖世英雄少女心 2021-01-01 11:52

I\'m calling this function:

function submit_button(button_id){
    $(\'#\' + button_id).attr(\'type\', \'submit\');
}

to make this button t

7条回答
  •  一生所求
    2021-01-01 12:09

    Why jQuery won't allow you to just change the type attribute?

    Because it causes problems in Internet Explorer.

    More info at: change type of input field with jQuery

    "Straight from the jQuery source":

    // We can't allow the type property to be changed (since it causes problems in IE)
    if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
        throw "type property can't be changed";
    

提交回复
热议问题