2013-03-13 84 views
1

我在Drupal 7主題中使用Jquery Mobile 1.0.1。 我想自定義後退按鈕,但不能更改數據值的屬性。JQuery Mobile - 以編程方式設置屬性

這是jQuery Mobile的加載之前插入腳本:

var $jqm = jQuery.noConflict(); 
    $jqm(document).bind("pageinit", function() { 
    console.log("mobileinit"); // Not loaded 
$jqm(".ui-btn-left").jqmData("icon", "arrow-l"); // Thus, not set 
}) 


$jqm(document).bind("mobileinit", function() { 
    console.log("mobileinit"); // This happens though 

    $jqm.mobile.ns = ''; 
    $jqm.mobile.autoInitializePage = 1; 
    $jqm.mobile.subPageUrlKey = 'ui-page'; 
    $jqm.mobile.activePageClass = 'ui-page-active'; 
    $jqm.mobile.activeBtnClass = 'ui-btn-active'; 
    $jqm.mobile.ajaxEnabled = 1; 
    $jqm.mobile.hashListeningEnabled = 1; 
    $jqm.mobile.defaultPageTransition = 'slide'; 
    $jqm.mobile.defaultDialogTransition = 'pop'; 
    $jqm.mobile.minScrollBack = 150; 
    $jqm.mobile.loadingMessage = 'indlæser'; 
    $jqm.mobile.pageLoadErrorMessage = 'Error'; 
    $jqm.mobile.linkBindingEnabled = 1; 
    $jqm.mobile.pushStateEnabled = 1; 
    $jqm.mobile.touchOverflowEnabled = 0;  

}); 

jQuery Mobile的後標記已結束的模樣

<a class="ui-btn-left ui-btn ui-btn-icon-left ui-btn-corner-all ui-shadow ui-btn-up-a"  data-ajax="false" data-icon="home" data-rel="home" title="Forsiden" href="/" data-theme="a"> <span class="ui-btn-inner ui-btn-corner-all"> <span class="ui-btn-text"> <span class="ui-icon ui-icon-home ui-icon-shadow"></span> </span> </a> 
+0

你能後置HTML標記? – Omar 2013-03-13 11:05:34

+0

Lasse 2013-03-13 11:57:35

+0

加載jqm後,可以在「pageinit」或「pagebeforeshow」事件中完成更改。將標記添加到您的問題主體:) – Omar 2013-03-13 12:11:25

回答

1

下面是如何更改主頁按鈕的圖標。更改data-icon不會更改圖標,因爲類ui-icon-home已添加到按鈕的第二個span。因此,不要更改data-icon,請刪除類ui-icon-home然後添加類ui-icon-arrow-l,請執行以下操作。

按鈕

<a data-role="button" data-ajax="false" data-icon="home" data-rel="home" title="Forsiden" href="/" data-theme="a">Home</a> 

JQM

$jqm(document).on("pageinit", function() { 
$jqm("[data-role='button'].ui-btn-left").buttonMarkup({icon: "arrow-l"}); 
}); 
+0

謝謝你的回答。嗯,我得到TypeError:$ jqm(...)。on不是函數。我試圖改爲$ jqm(...)。但是這並沒有幫助。 我無法修改標記 - 這是由drupal(簡單A標記)生成的。 – Lasse 2013-03-13 14:00:20

+0

嘗試刪除並檢查它是否有效。 – Omar 2013-03-13 15:09:11

相關問題