jquery date picker show only month with .css issue

青春壹個敷衍的年華 提交于 2019-12-12 02:23:09

问题


I want to change datepicker to select month only. I can change with change css property like this

    <!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>


</head>
<body style="font-size:62.5%;">

 <input class="todaydate" type="text"   name="todaydate" />
<p>test paragraph</p>
<script>
    $('.todaydate').datepicker();


</script>
<style>
.ui-datepicker-calendar {
    display: none;
    }
</style>
</body>
</html>

It works, but when I want to change css with jquery like this, it not work

<script>
    $('.todaydate').datepicker();
$('.ui-datepicker-calendar').css({display:'none'})
</script>

Help me please


回答1:


1) is there javascript error in your console? 2) if i'm not wrong this $('.ui-datepicker-calendar').css({display:'none'}) works for html elements. http://api.jquery.com/css/ http://api.jquery.com/category/selectors/ 3) try to put your script below whatever you want to select as html rendering starts from top to bottom. ......

.....


回答2:


It's because you need a document.ready. Do this:

<script>
  $(document).ready(function(){
     $('.todaydate').datepicker();
     $('.ui-datepicker-calendar').css({display:'none'})
  });
</script>

Hope this helps. Cheers




回答3:


supposing you want to hide the calendar using jquery and not css for some weird reason of yours. you can try this:

$('.todaydate').datepicker();
$('.todaydate').click(function(){
   $('.ui-datepicker-calendar').css('display','none');
});

check it out live here... http://jsfiddle.net/FRQ2D/

it will hide the calendar with no problem, but I'm not sure how you gonna select just the month xD (maybe with some blur() magic :P).

there's no event call to trigger the .css() so your coding there is bad...



来源:https://stackoverflow.com/questions/5908521/jquery-date-picker-show-only-month-with-css-issue

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