change type of input field with jQuery

后端 未结 29 2613
青春惊慌失措
青春惊慌失措 2020-11-22 05:13
$(document).ready(function() {
    // #login-box password field
    $(\'#password\').attr(\'type\', \'text\');
    $(\'#passwo         


        
29条回答
  •  梦如初夏
    2020-11-22 05:54

    I haven't tested in IE (since I needed this for an iPad site) - a form I couldn't change the HTML but I could add JS:

    document.getElementById('phonenumber').type = 'tel';
    

    (Old school JS is ugly next to all the jQuery!)

    But, http://bugs.jquery.com/ticket/1957 links to MSDN: "As of Microsoft Internet Explorer 5, the type property is read/write-once, but only when an input element is created with the createElement method and before it is added to the document." so maybe you could duplicate the element, change the type, add to DOM and remove the old one?

提交回复
热议问题