2014-02-06 31 views
-1

我在MVC項目中有問題。爲什麼在線Jquery Datepicker工作,但本地Jquery Datepicker不能在MVC項目中工作

我已經通過添加此代碼create.cshtml測試:

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> 
<script src="//code.jquery.com/jquery-1.9.1.js"></script> 
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 

<script> 
$(function() { 
$("#datepicker").datepicker(); 
}); 

和文本框中輸入:

<input type="text" id="datepicker"> 

和它的工作,當我點擊或按下文本框,日期選擇器彈出窗口顯示出來。

,但是當我想在我的電腦本地運行在_layout.cshtml把這個JavaScript和CSS文件(表現在所有的頁面一般):

@Scripts.Render("~/Scripts/jquery-1.9.1.js") 
@Scripts.Render("~/Scripts/jquery-ui.js") 
@Styles.Render("~/Content/themes/base/jquery-ui.css") 
@RenderSection("scripts", required: false) 

重標記直接鏈接到網上的jQuery (源)在我的create.cshtml,之後,我運行該頁面不會顯示datepicker,我缺少這個問題的東西?

PS:我已經保存jQuery的1.9.1.js,jQuery的ui.js,jQuery的ui.css在本地PC

+1

你提到了當地的jQuery文件的路徑是不正確的 –

+0

使用Chrome檢查找到正確的路徑。 – ankur140290

+0

@ HussainAkhtarWahid'Ghouri'我已經使用phoenix編輯器來查看在firefox中運行的文件,文件.js和.css被加載,但仍然不起作用。 –

回答

0

因爲你的文件的路徑當地失蹤。

<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> 
<script src="//code.jquery.com/jquery-1.9.1.js"></script> 
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 

更改爲

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> 
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
+0

是不是這樣,第一個代碼正常工作,但是當我註釋該代碼並在_layout.cshtml, '@ Scripts.Render(「〜/ Scripts/jquery-1.9.1.js」)中添加鏈接 @ Scripts.Render(「〜/ Scripts/jquery-ui.js」) @ Styles.Render(「〜/ Content/themes/base/jquery-ui.css」) @RenderSection(「scripts」,required:false) ' 然後創建頁面無法正常工作[它似乎.js不是全球工作] –