Using jQuery trying to change background-color of text box but not working in wordpress

前端 未结 1 953
温柔的废话
温柔的废话 2021-01-22 18:23

Here is jQuery code which I am using .




        
1条回答
  •  北海茫月
    2021-01-22 18:53

    The color code needs a prepending # to be used with CSS.

    Change

    jQuery('#my_txtbox_id').css('background-color',color);
    

    To

    jQuery('#my_txtbox_id').css('background-color', '#' + color);
    

    Edit: You can further optimize the code like so:

    jQuery(document).ready(function ($) {
        $('.jscolor').on('change', function (e) {
            var color = $(this).val();
            $('#my_txtbox_id').val(color).css('background-color', '#' + color);
        });
    });
    

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