我在我的html模板中有一個電子郵件按鈕,單擊該按鈕打開一個對話框,顯示用戶的電子郵件。在該電子郵件下方,我有一個鏈接(在對話框中)。我需要在打開該對話框之前將其轉換爲jquery按鈕。Jquery - 將鏈接轉換爲對話框中的按鈕
我可以手動把它轉換成一個按鈕
alertDialog.find('a').button();
,但我並不想用這個作爲罐頭,因爲這是在渲染慢。
請你能不能幫
我在我的html模板中有一個電子郵件按鈕,單擊該按鈕打開一個對話框,顯示用戶的電子郵件。在該電子郵件下方,我有一個鏈接(在對話框中)。我需要在打開該對話框之前將其轉換爲jquery按鈕。Jquery - 將鏈接轉換爲對話框中的按鈕
我可以手動把它轉換成一個按鈕
alertDialog.find('a').button();
,但我並不想用這個作爲罐頭,因爲這是在渲染慢。
請你能不能幫
試試這個: -
alertDialog.find('a').addClass("yourClass");
.yourClass{
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.428571429;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
border: 1px solid transparent;
border-radius: 4px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
謝謝。但添加一個類,我需要包括一個新的CSS。我忽略了這一點。這也是一個很好的解決方案.. –
不需要新的CSS,只需要你現有的CSS中的一個類。 – Anup
使用jQuery的replaceWith
方法:
alertDialog.find('a').each(function (_, e) {
$(e).replaceWith($('<button/>', {
text: e.innerHTML
}).on('click', function() {
window.location.href = e.href;
}))
});
感謝您的及時回覆。但這不適合我。 –
它工作在jsfiddle http://jsfiddle.net/UyWg8/,所以我想你是在別的地方做錯了什麼,或者我不明白你在找什麼 –
是的,謝謝你我錯了'.on('點擊',function())'。 –
'.button()'是不是一個jQuery方法。你是否使用twitter js,如果你應該告訴它有問題或者說你在使用哪個插件。編輯:對不起,看起來像你反正不想使用它 –
應用它看起來像按鈕類。 – Anup
我想你可以使用replaceWith方法 –