简体   繁体   中英

jQuery: autofill input values with mouse click not keyboard

I'm using this solution https://stackoverflow.com/a/4932770/3108268

$("#EmailAddress").keyup(function(){
    $("#Username").val(this.value);
});

And it works fine when typing input values with a keyboard, it auto fills the selected field.

But it doesn't work when filling a field with a mouse click from calendar popup javascript plugin. The popup plugin gives the input classes hasDatepicker date-popup-init .

This is all inside Drupal 7, but I don't think it's relevant.

Here's an example, as you can see the time field is plain text and autofills below, because it is being filled with a keyboard while filling the date field with mouse click from calendar popup does not fill the field below it (but does if you force-type with keyboard).

在此处输入图片说明

You could use change event;

$( "#EmailAddress" ).change(function() {
  $("#Username").val(this.value);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM