问题
I'm trying to use materialize date picker (http://materializecss.com/forms.html). With that, I want to popup the date picker when I click on an icon. I have implemented two implementations where the only difference between the two is putting an alert('clicked') with the code.
without the alert('clicked'): http://jsfiddle.net/1bnnkhbw/
with the alert('clicked'): http://jsfiddle.net/1bnnkhbw/1/
The second one works while the first one doesn't.. (in chrome)!!!
Anybody knows the reason for this behavior?
And a way to make the 1st one work?
回答1:
I think I found a solution for you man check this out:
<i id="icon">click</i>
<input class="datepicker" style="display:none;" value="click"></input>
$('.datepicker').pickadate({
selectMonths: true,
selectYears: 15
});
$('#icon').click(function(event){
event.stopPropagation();
$(".datepicker").first().pickadate("picker").open();
console.log("test1");
});
Fiddle: http://jsfiddle.net/k2qtzp7p/1/
Code taken from here and here
来源:https://stackoverflow.com/questions/29832007/strange-behaviour-in-material-datepicker