2011-07-13 30 views
0

夠簡單了,我希望。我想,當我在jQuery的日期選擇器點擊日期以獲得股利淡入:語法使用與ONSELECT jQuery的日期選擇器

<!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> 
    <script type="text/javascript" src="../datepicker/jquery.ui.core.js"></script> 
    <script type="text/javascript" src="../datepicker/jquery.ui.widget.js"></script> 
    <script type="text/javascript" src="../datepicker/jquery.ui.datepicker.js"></script> 

    <script> 
    $(document).ready(function() { 
    $('#datepicker').datepicker(); 
    $('#datepicker').datepicker({ 
     onSelect: function(dateText, inst) { 
     $('#foo').fadeIn(); 
     }); 
    }); 
    }); 
    </script> 
</head> 
<body style="font-size:62.5%;"> 

<p>Choose a date: <input id="datepicker" type="text"></p> 

<div id="foo">FOO</div> 

</body> 
</html> 

回答

1

1.你的代碼中有一個額外的括號和分號,請參見下面的代碼註釋:

$(document).ready(function() { 
    $('#datepicker').datepicker(); 
    $('#datepicker').datepicker({ 
     onSelect: function(dateText, inst) { 
     $('#foo').fadeIn(); 
     }); // <-- HERE, it should be just } 
    }); 
}); 

這是正確的代碼:

$(document).ready(function() { 
    $('#datepicker').datepicker({ 
     onSelect: function(dateText, inst) { 
      $('#foo').fadeIn(); 
     } 
    }); 
}); 

2.沒有必要附加datepicker()兩次相同的元素,你只要給它分配一次,用適當的參數,因此爲什麼我刪除了額外的$('#datepicker').datepicker()

3.您應該隱藏,以便它仍然隱藏,直到你消失它的元素使用這個CSS:

#foo{ 
    display: none; 
} 

Check a demo here »

+1

輝煌。感謝您的頭對風格了。 – Adam

0

您對您的JavaScript有錯誤,另外一個問題是,你不能淡入()的元素是可見:你必須先隱藏它。

試試這個:

$(document).ready(function() { 
    $('#foo').hide(); 
    $('#datepicker').datepicker({ 
     onSelect: function(dateText, inst) { 
      $('#foo').fadeIn(); 
     } 
    }); 

    }); 

小提琴:http://jsfiddle.net/vH4HV/1/

相關問題