jquery mobile 动态加载标签时,无法正常展示样式
2015-11-19 22:01
771 查看
原因
在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
在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
相关文章推荐
- jQuery Mobile 学习笔记(一)
- jQuery 下载
- 12个用于播放音乐和视频文件的jQuery插件
- 关于jquery文件上传插件 uploadify 3.1的使用
- jquery写的90度翻转
- jquery uploadify插件多文件上传
- jQuery选择器汇总
- jQuery和D3两种版本输入框长度控制
- jQuery高级事件
- jQuery 操作复选框(checkbox) attr checked不起作用
- jQuery插件之ajaxFileUpload API文档
- jQuery框架收集
- 理解jquery的$.extend()、$.fn和$.fn.extend()
- jquery中的ajax方法参数
- 十五个常用的jquery代码段【转】
- JQuery.Ajax之错误调试帮助信息
- jquery总结--有道笔记整理
- jquery tmpl 详解
- jquery $.proxy使用
- jQuery-1.9.1源码分析系列(十) 事件系统——事件委托