2017-05-06 47 views
-1

據我所知,jQuery有衝突。我怎麼能解決jQuery conlicts至於「bootstrap.min.js」「jquery.min.js」是必要的。 這裏是我的代碼:

<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet"> 
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script> 
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 

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

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<link rel="stylesheet" type="text/css" href="doctor.css"> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
+0

'我怎麼能解決的jQuery conlicts'只有** **一次申報每請求在您的頁面頂部的libray,即:在標題 – OldPadawan

回答

0

您可以將jQuery腳本標記加載後調用var jquery_version = jQuery.noConflict()並在以後使用它使用jquery_version。 jQuery documentation

+0

這與這個問題有什麼關係? –

+0

網頁包含兩個jQuery版本 –

+0

你能舉一個例子說明如何做到這一點嗎?目前,這似乎是在' 創建'

1

問題是因爲您正在加載兩個不同版本的jQuery,1.10.23.2.0。由於它們被添加到頁面的順序,第二個實例沒有jQueryUI方法。

雖然可以在頁面中包含多個jQuery版本,但應儘可能避免使用jQuery,因爲它不是一個可維護的解決方案。爲了解決這個問題,你應該改變你的代碼使用jQuery的單個實例,像這樣:

<link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet"> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<link rel="stylesheet" type="text/css" href="doctor.css"> 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> 
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
<script> 
    $(function() { 
    $("#datepicker").datepicker(); 
    }); 
</script> 
+0

代替代碼後,沒有錯誤,但datepicker()不工作,我的意思是我沒有看到日曆類型後點擊任何文字字段。 – progga

+0

它似乎在小提琴中工作正常:https://jsfiddle.net/6jqqedtw/。檢查控制檯是否有錯誤。 –

0

使用noConflict選項。檢查連接的片段

<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet"> 
 
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 

 

 
<script> 
 
    var jqOld = jQuery.noConflict(); 
 
    jqOld(function() { 
 
     jqOld("#datepicker").datepicker(); 
 
    }) 
 
</script> 
 

 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
<link rel="stylesheet" type="text/css" href="doctor.css"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 
<input id = "datepicker"/>

0

你掛的兩個jQuery的文件& 2 jQuery UI的文件,刪除一個

相關問題