2012-11-09 44 views
0

我在jsp中使用jQuery 1.8.2,jQuery ui 1.9.1,Firefox 16.0.1,我試圖讓按鈕顯示一個圖標。我試過了:如何在按鈕中使用jQuery設置默認圖標

$('button').button({ icons: {primary: "ui-icon-triangle-1-s" } }); 

,並在div:

<div id="buttonDiv" style="text-align: center;"> <button class="btn-primary" type="button" id="confirmationButton" value="confirm">Confirmation</button> </div> 

,然後我試着用一個ID,一個類,類型設置爲按鈕,等等,但由於某種原因它不顯示。

我知道,如果我試圖使按鍵輸入按鈕,這將不會被設計工作,當我使用

$('button').button()等。作爲一個選擇它的正常工作。

這裏是我的CDN聲明:

<!-- Reference the theme's stylesheet on the Google CDN --> 
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/> 

    <!-- Reference jQuery and jQuery UI from the CDN. Remember that the order of these two elements is important --> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script> 

缺少什麼我在這裏?

回答

1

你確定你沒有錯過任何其他資源嗎?你是否包含了所需的CSS和圖像?

具體jQuery的ui.css: http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.csshttp://code.jquery.com/ui/1.9.1/themes/base/images/ui-icons_222222_256x240.png

編輯:

使用腳本標籤的,我很快就寫了這件事和它的作品。

<!doctype html> 
    <html> 
    <head> 
     <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script> 
     <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script> 
     <script type="text/javascript"> 
     $(document).ready(function(){ 
      $('button').button({ icons: {primary: "ui-icon-triangle-1-s" } }); 
     }); 
     </script> 
     </head> 
    <body> 
     <div id="buttonDiv" style="text-align: center;"> <button class="btn-primary" type="button" id="confirmationButton" value="confirm">Confirmation</button> </div> 
    </body> 
    </html> 
+0

我錯過了對圖標本身的引用。所以如果我選擇一個主題,我也必須參考這些圖標? –

+0

我編輯了我原來的答案。來自google的遠程jquery-ui.css使用圖像的相對路徑,我推測這些路徑使用http://ajax.googlepais.com/...作爲其絕對路徑擴展。 – Brian

+0

我有一切權利,但我現在看到它,我遺漏了我的按鈕語句函數。我忽略在這裏檢查明顯的。謝謝! –

相關問題