Changing the “placeholder” attribute of HTML5 input elements dynamically using Javascript

后端 未结 6 1152
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 16:03

I\'m trying to dynamically update the HTML5 placeholder attribute of a text field using jQuery.

$(\"textarea\").attr(\"placeholder\", \"New plac         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 16:37

    working example of dynamic placeholder using Javascript and Jquery http://jsfiddle.net/ogk2L14n/1/

    
     
    
    function changeplh(){
        debugger;
     var sel = document.getElementById("selection");
        var textbx = document.getElementById("textbox");
        var indexe = sel.selectedIndex;
    
        if(indexe == 0) { 
         $("#textbox").attr("placeholder", "age");
    
    }
           if(indexe == 1) { 
         $("#textbox").attr("placeholder", "name");
    }
    }
    

提交回复
热议问题