Changing the <input> type in IE with JavaScript

前端 未结 4 1910
旧巷少年郎
旧巷少年郎 2020-11-28 15:15

This code below works in all web browsers except IE:



        
4条回答
  •  执念已碎
    2020-11-28 15:51

    You cannot dynamically change a the type of an input element in Internet Explorer.

    One possible workaround would be to:

    • Dynamically create a new element.
    • Copy the properties of the old element into the new element.
    • Set the type of the new element to the new type.
    • Then replace the old element with the new element.

    You may want to check the following article for a JavaScript implantation of the above:

    • Change Input Element Type using JavaScript

    Another option would be to statically create the two elements, but having only one visible at a time. The visibility and the focus would depend on the value of the elements. In this case, you may want to use something like this:

    
    
    
    
    

提交回复
热议问题