Strange behaviour in Material datepicker

偶尔善良 提交于 2019-12-10 16:24:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!