Change Placeholder Text using jQuery

后端 未结 13 1231
-上瘾入骨i
-上瘾入骨i 2020-12-04 06:17

I am using a jQuery placeholder plugin(https://github.com/danielstocks/jQuery-Placeholder). I need to change the placeholder text with the change in dropdown menu. But it is

相关标签:
13条回答
  • 2020-12-04 06:50

    simply you can use

    $("#yourtextboxid").attr("placeholder", "variable");
    

    where, if variable is string then you can use like above, if it is variable replace it with the name like "variable" with out double quotes.

    eg: $("#youtextboxid").attr("placeholder", variable); it will work.

    0 讨论(0)
  • 2020-12-04 06:55
    $(document).ready(function(){ 
         $("input[type=search]").attr("placeholder","this is a test");
    });
    
    0 讨论(0)
  • 2020-12-04 06:56

    The plugin doesn't look very robust. If you call .placeholder() again, it creates a new Placeholder instance while events are still bound to the old one.

    Looking at the code, it looks like you could do:

    $("#serMemtb").attr("placeholder", "Type a name (Lastname, Firstname)").blur();
    

    EDIT

    placeholder is an HTML5 attribute, guess who's not supporting it?

    Your plugin doesn't really seem to help you overcome the fact that IE doesn't support it, so while my solution works, your plugin doesn't. Why don't you find one that does.

    0 讨论(0)
  • 2020-12-04 06:56

    this worked for me:

    jQuery('form').attr("placeholder","Wert eingeben");
    

    but now this don't work:

    // Prioritize "important" elements on medium.
                skel.on('+medium -medium', function() {
                    jQuery.prioritize(
                        '.important\\28 medium\\29',
                        skel.breakpoint('medium').active
                    );
                });
    
    0 讨论(0)
  • 2020-12-04 06:59

    Moving your first line to the bottom does it for me: http://jsfiddle.net/tcloninger/SEmNX/

    $(function () {
        $('#serMemdd').change(function () {
            var k = $(this).val();
            if (k == 1) {
                $("#serMemtb").attr("placeholder", "Type a name (Lastname, Firstname)").placeholder();
            }
            else if (k == 2) {
                $("#serMemtb").attr("placeholder", "Type an ID").placeholder();
            }
            else if (k == 3) {
                $("#serMemtb").attr("placeholder", "Type a Location").placeholder();
            }
        });
        $('input[placeholder], textarea[placeholder]').placeholder();
    });
    
    0 讨论(0)
  • 2020-12-04 07:02

    You can use following code to update a placeholder by id:

    $("#serMemtb").attr("placeholder", "Type a Location").val("").focus().blur();
    
    0 讨论(0)
提交回复
热议问题