2011-11-24 20 views
0

我現在用的是笨的框架,並試圖使用jquery用於顯示和允許用戶選擇,他希望他的瓶坯搜索的時間週期爲目的的日曆。我有日期和文本字段顯示,但是當我點擊文本字段時,我沒有任何日曆從中選擇日期。 這是我的看法:試圖顯示使用jQuery UI的

<html> 
<head> 
<script type="text/javascript" src="<?php echo $jquery?>"></script>   
<script type="text/javascript"> 
$(function() { 
    $("#datepicker").ui-datepicker(); 
}); 

</script> 
</head> 
<body> 
<div class="demo"> 

<p>Date: <input id="datepicker" type="text"></p> 

</div><!-- End demo --> 



<div style="display: none;" class="demo-description"> 
<p>The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.</p> 
</div><!-- End demo-description --> 

<a href="">www.msn.ca</a> 
<?php echo form_open('search/submit'); ?> 
</body> 
</html> 

它取自示例代碼:http://jqueryui.com/demos/datepicker/ 僅供參考我使用jQuery UI 16年8月1日 不知道什麼是錯在這裏。 如果有人認爲該控制器是相關的,然後在這裏它是:

<?php 
class calendarController extends CI_Controller{ 

    public function index() 
    { 
     $this->load->helper('url'); 
     $data['jquery'] = base_url("jquery.js"); 
     $this->load->view("jqueryView", $data); 
    } 
} 
?> 

回答

1

我沒有看到你網頁上的鏈接到jQuery的JS和CSS文件。試試這樣的:

<link href="Content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> 
<script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>  
<script src="Scripts/jquery-ui-1.8.16.min.js" type="text/javascript"></script> 

你可以將它們放在你的頁面的任何地方。最後更好,以便您的頁面顯示更快。在代碼中使用日期選擇器()jQuery的負載功能裏面,像以確保沒有被打破

+0

我應該將它們添加到身體或頭? –

+0

jQuery UI當然取決於jQuery,所以jquery-1.7.min.js應該在jquery-ui-1.8.16之上,對此很抱歉。 – AFD

+0

這很好。我知道了。謝謝:) –

0

你不應該把你的日期選擇器初始化jQuery的準備好事件處理中?

像這樣:

$(document).ready(function(){ 

    $("#datepicker").datepicker(); 

}); 
+1

$(函數(){$ ( 「#datepicker」).datepicker(); }); 幾乎是一樣的。 – AFD

0

您建立您的網址錯誤。

應該是:

$data['jquery'] = base_url().'jquery.js'; 

,其給出了自己的看法:http://www.yoursite.com/jquery.js.

我對劇本的實際真實位置有些懷疑。因此將其更改爲您的文件夾結構,只需記住,base_url()返回您的網址是這樣,與結尾的斜線:

http://www.yoursite.com/ 

而且,你,你不裝載 jQuery UI的,所以加太(同樣的方式如上)

另一件事,您輸入缺少name屬性,你需要它的情況下,你希望它通過PHP獲取。而且,它不在表單中,所以它不起作用。這僅僅是一個音符,也許你並不想用這種方式,但以防萬一...

+0

我居然得到了下一個錯誤,當我再補充一點點:未定義的常量BASE_URL用途 - 假設「BASE_URL」 –

+0

因爲你不使用圓括號你得到它。這是BASE_URL(),而不是BASE_URL –

+0

所以如果它與BASE_URL工作這意味着,編譯器編輯它BASE_URL()? –