2013-02-06 25 views
6

我有一個提交按鈕我的網頁下面的代碼: 的HTML標記是:加入jQuery UI的圖標,一個提交按鈕

<td align="Right"><input type="submit" value="Add Driver" ></td> 

和jQuery是:

$("input[type=submit]").button().click(function(event) { 
event.preventDefault(); 
}); 

會如何我在上面添加了一個UI圖標,具體是ui-icon-circle-plus

回答

5

你可以改變你的HTML這樣的:

<button type="submit"> 
    Add Driver 
</button> 

,然後更新您的腳本像這樣的:

$('button[type=submit]').button({icons: {primary: 'ui-icon-circle-plus'}}).click(function (event) { 
    event.preventDefault(); 
}); 

演示:http://jsfiddle.net/mh5Pu/

1

這應該可以工作

$("input[type=submit]").button({icons: {primary: "ui-icon-circle-plus"}})  .click(function(event) { 
event.preventDefault(); 
}); 

,或者你把它算賬:

$("input[type=submit]").button("option", "icons", { primary: "ui-icon-circle-plus", secondary: "<your_second_icon>" }); 

Here是一個工作示例。

+0

我試過了,但是沒有效果 –

+0

看看這個:http://jsfiddle.net/Kfubw/ 你的HTML語法也有錯誤:這是正確的HTML: Laokoon

1

看看http://jqueryui.com/button/#icons(特別是圖標)的例子。

而不是使用提交輸入,請嘗試使用按鈕。

這裏的圖標只與UI圖標的圓加號按鈕的改進版本:

<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"  role="button" aria-disabled="false" title="Button with icon only"> 
<span class="ui-button-icon-primary ui-icon ui-icon-circle-plus"></span> 
<span class="ui-button-text">Button with icon only</span> 
</button>