を持っています input type="text"
に変換したい input type="button"
。私が試してみました attr()
、 でもあの 動作しません:
HTML:
<input type="text"></input>
JavaScript:
$("input").attr("type", "button");
どうしましたか?
回答:
回答№1は6変更できません type
jQueryを使った属性これはjQueryからのものです ソース:
// We can"t allow the type property to be changed (since it causes problems in IE)
if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
jQuery.error( "type property can"t be changed" );
}
その理由は、コメントによれば、それがIEで問題を引き起こします。 jQueryはブラウザ間の違いによって生じる複雑さを軽減するように設計されているので、他のブラウザでもうまくいかなければその考えに反するでしょう。 jQueryチームが単にその能力を取り除いたのはそのためだと思います。
すでに述べたように、おそらくあなたの最良の選択肢は input
問題の要素に新しい要素を追加します。
回答№2の場合は0
これは部分的にカバーされています ドキュメンテーション:
注意: Internet Explorerではタイプを変更できません の属性
<input>
または<button>
素子。
どのブラウザでもこれを試みることさえできないのは、jQueryのソースから来ています。
// 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";
(ドキュメントを更新する必要があるようです。)