简体   繁体   中英

Jquery click not working for input element at first

I got a jquery date selector from internet and the script was like this...

<script type="text/javascript">
$(document).ready(function () {
$("#date3").click(function(){
$("#date3").scroller({ preset: 'datetime' });
wheels = [];
wheels[0] = { 'Hours': {} };
wheels[1] = { 'Minutes': {} };
for (var i = 0; i < 60; i++) {
if (i < 16) wheels[0]['Hours'][i] = (i < 10) ? ('0' + i) : i;
wheels[1]['Minutes'][i] = (i < 10) ? ('0' + i) : i;
}
});
});
</script>

My problem is that when i first click the input textbox, it doesn't work. I've to click on the textbox first, click somewhere else in the page, and then again click on the textbox to make it work. Is there any way to solve it?

If you want to solve without change your code you can do like this:-- when your page will load it will work fine now..

<!-- creating a dummy button and clicking on it -->
<div style="display: none;"><input type="submit" id="dummy_btn" value="Dummy Btn" /></div>

jQuery('#dummy_btn').trigger('click'); 
});

jQuery(function(){  
   jQuery('#submitid').click(function(){

    });
    jQuery('#dummy_btn').trigger('click'); 
});

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