jquery mobile 動態加載標簽時,無法正常展示樣式


原因

  在chrome中審查元素,發現其增加了很多沒有直接寫在頁面上的標簽和樣式。頁面標簽首先經過jquery.mobile-1.4.5.min.js的處理,添加了許多標簽,然后再用css布局

解決方案

1.將jquery.mobile-1.4.5.min.js處理后的樣式動態添加,即將chrome中審查元素得到的完整元素及樣式復制下來,動態添加

缺點:代碼很多,而且加了很多奇怪樣式和各種標簽

2.refresh

各類標簽的刷新

1.Textarea fields

$('body').prepend('<textarea id="myTextArea"></textarea>');
$('#myTextArea').textinput();

-------------------------------------------------------------
2.Text input fields

$('body').prepend('<input type="text" id="myTextField" />');
$('#myTextField').textinput();

-------------------------------------------------------------

3.Buttons

$('body').append('<a href="" data-theme="e" id="myNewButton">testing</a>'); $('#myNewButton').button();

-------------------------------------------------------------

4.Combobox or select dropdowns

<label for="sCountry">Country:</label>
<select name="sCountry" id="sCountry">
    <option value="">Where You Live:</option>
    <option value="ad">Andorra</option>
    <option value="ae">United Arab Emirates</option>
</select>

var myselect = $("#sCountry");
myselect[0].selectedIndex = 3;
myselect.selectmenu('refresh');

-------------------------------------------------------------

5.Listviews

<ul id="myList" data-role="listview" data-inset="true">
    <li>Acura</li>
    <li>Audi</li>
    <li>BMW</li>
</ul>

$('#mylist').listview('refresh');

-------------------------------------------------------------

6.Slider control

<div data-role="fieldcontain">
    <label for="slider-2">Input slider:</label>
    <input type="range" id="slider-2" value="25" min="0" max="100" />
</div>

$('#slider-2').val(80).slider('refresh');

-------------------------------------------------------------

7.Toggle switch

<div data-role="fieldcontain">
    <label for="toggle">Flip switch:</label>
    <select name="toggle" id="toggle" data-role="slider">
        <option value="off">Off</option>
        <option value="on">On</option>
    </select>
</div>

var myswitch = $("#toggle");
myswitch[0].selectedIndex = 1;
myswitch .slider("refresh");

-------------------------------------------------------------

8.Radio buttons

<div data-role="fieldcontain">
    <fieldset data-role="controlgroup" data-type="horizontal">
        <legend>Layout view:</legend>
        <input type="radio" name="radio-view" value="list" />
        <label for="radio-view-a">List</label>
        <input type="radio" name="radio-view" value="grid" />
        <label for="radio-view-b">Grid</label>
        <input type="radio" name="radio-view" value="gallery" />
        <label for="radio-view-c">Gallery</label>
    </fieldset>
</div>
$("input[value=grid]").attr('checked',true).checkboxradio('refresh');

-------------------------------------------------------------

9.Checkboxes

<div data-role="fieldcontain">
    <fieldset data-role="controlgroup">
        <legend>Agree to the terms:</legend>
        <input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
        <label for="checkbox-1">I agree</label>
    </fieldset>
</div>

$('#checkbox-1').attr('checked',true).checkboxradio('refresh');

-------------------------------------------------------------

10.controlgroup
            
$("#fieldNextNode").trigger('create');//發生cannot call methods on checkboxradio prior to initialization; attempted to call method 'refresh'……錯誤時
$("#fieldNextNode").controlgroup("refresh");

 

參考資料:

http://blog.csdn.net/lgd5979/article/details/7161339


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM