Event handler for a html5 color input element

后端 未结 3 565
南方客
南方客 2020-12-18 19:11

Using the new input=\"color\" element within Chrome triggers a new popup dialog:

\"screenshot

相关标签:
3条回答
  • 2020-12-18 19:36

    What you are looking for is the input event.

    Your modified fiddle should now work in all (decent) browsers:

    $('#colorinput').on('input', function() { ... } )
    
    0 讨论(0)
  • 2020-12-18 19:36

    To get the value of color input, you should use the event attribute onchangeprovided in w3school

    <input name="eventColor" type="color" onchange="getColorVal(eventColor.value)"/>
    

    and define a function that handle the event

     function getColorVal(colorValue){
    
         alert(colorValue);
    }
    
    0 讨论(0)
  • 2020-12-18 19:48

    You really want input event per HTML spec. Nothing guarantees change event to fire before the input element has lost focus.

    "The input event fires whenever the user has modified the data of the control. The change event fires when the value is committed, if that makes sense for the control, or else when the control loses focus. "

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