jQuery change input text value

后端 未结 5 1871
刺人心
刺人心 2020-11-28 02:12

I can\'t find the right selector for:




        
相关标签:
5条回答
  • 2020-11-28 02:44

    Best practice is using the identify directly:

    $('#id').val('xxx');

    0 讨论(0)
  • 2020-11-28 02:45

    no, you need to do something like:

    $('input.sitebg').val('000000');
    

    but you should really be using unique IDs if you can.

    You can also get more specific, such as:

    $('input[type=text].sitebg').val('000000');
    

    EDIT:

    do this to find your input based on the name attribute:

    $('input[name=sitebg]').val('000000');
    
    0 讨论(0)
  • 2020-11-28 02:52

    When set the new value of element, you need call trigger change.

    $('element').val(newValue).trigger('change');

    0 讨论(0)
  • 2020-11-28 02:55

    jQuery way to change value on text input field is:

    $('#colorpickerField1').attr('value', '#000000')
    

    this will change attribute value for the DOM element with ID #colorpickerField1 from #EEEEEE to #000000

    0 讨论(0)
  • 2020-11-28 02:59

    Just adding to Jason's answer, the . selector is only for classes. If you want to select something other than the element, id, or class, you need to wrap it in square brackets.

    e.g.

    $('element[attr=val]')

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