Adding placeholder attribute using Jquery

后端 未结 4 1603
面向向阳花
面向向阳花 2021-02-05 05:37

I have a simple problem. I just want to add a placeholder on an input. Here\'s the code:

HTML:


JQuery         


        
相关标签:
4条回答
  • 2021-02-05 06:03

    Try something like the following if you want to use pure JavaScript:

    document.getElementsByName('link')[0].placeholder='Type here to search';
    
    0 讨论(0)
  • 2021-02-05 06:08

    You just need this:

    $(".hidden").attr("placeholder", "Type here to search");
    

    classList is used for manipulating classes and not attributes.

    0 讨论(0)
  • 2021-02-05 06:14

    you just need to put this

    ($('#{{ form.email.id_for_label }}').attr("placeholder","Work email address"));

    ($('#{{ form.password1.id_for_label }}').attr("placeholder","Password"));

    0 讨论(0)
  • 2021-02-05 06:17

    This line of code might not work in IE 8 because of native support problems.

    $(".hidden").attr("placeholder", "Type here to search");
    

    You can try importing a JQuery placeholder plugin for this task. Simply import it to your libraries and initiate from the sample code below.

    $('input, textarea').placeholder();
    
    0 讨论(0)
提交回复
热议问题