Change Placeholder Text using jQuery

后端 未结 13 1247
-上瘾入骨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 07:04

    $(this).val() is a string. Use parseInt($(this).val(), 10) or check for '1'. The ten is to denote base 10.

    $(function () {
        $('input[placeholder], textarea[placeholder]').blur();
        $('#serMemdd').change(function () {
            var k = $(this).val();
            if (k == '1') {
                $("#serMemtb").attr("placeholder", "Type a name (Lastname, Firstname)").blur();
            }
            else if (k == '2') {
                $("#serMemtb").attr("placeholder", "Type an ID").blur();
            }
            else if (k == '3') {
                $("#serMemtb").attr("placeholder", "Type a Location").blur();
            }
        });
    });
    

    Or

    $(function () {
        $('input[placeholder], textarea[placeholder]').placeholder();
        $('#serMemdd').change(function () {
            var k = parseInt($(this).val(), 10);
            if (k == 1) {
                $("#serMemtb").attr("placeholder", "Type a name (Lastname, Firstname)").blur();
            }
            else if (k == 2) {
                $("#serMemtb").attr("placeholder", "Type an ID").blur();
            }
            else if (k == 3) {
                $("#serMemtb").attr("placeholder", "Type a Location").blur();
            }
        });
    });
    

    Other Plugins

    ori has brought to my attention that the plugin you are using does not overcome IEs HTML failure.

    Try something like this: http://archive.plugins.jquery.com/project/input-placeholder

    0 讨论(0)
提交回复
热议问题