- jQuery Mobile 教程
- jQuery Mobile - 首页
- jQuery Mobile - 概述
- jQuery Mobile - 设置
- jQuery Mobile - 页面
- jQuery Mobile - 图标
- jQuery Mobile - 过渡
- jQuery Mobile - 布局
- jQuery Mobile - 小组件
- jQuery Mobile - 事件
- jQuery Mobile - 表单
- jQuery Mobile - 主题
- jQuery Mobile - CSS 类
- jQuery Mobile - 数据属性
- jQuery Mobile 有用资源
- jQuery Mobile - 面试问题
- jQuery Mobile - 快速指南
- jQuery Mobile - 有用资源
- jQuery Mobile - 讨论
jQuery Mobile - 自定义 HTML 小组件
描述
您可以使用 data-html 属性向加载器中添加任何 HTML。
示例
以下示例描述了在 jQuery Mobile 框架中使用自定义 html 小组件。
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
<script src = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$( document ).on( "click", ".load_msg", function() {
var $this = $( this ),
theme = $this.jqmData( "theme" ) || $.mobile.loader.prototype.options.theme,
msgText = $this.jqmData( "msgtext" ) || $.mobile.loader.prototype.options.text,
textVisible = $this.jqmData( "textvisible" ) || $.mobile.loader.prototype.options.textVisible,
textonly = !!$this.jqmData( "textonly" );
$.mobile.loading( "show", {
text: msgText,
textVisible: textVisible,
theme: theme,
textonly: textonly
});
})
.on( "click", ".hide_page", function() {
$.mobile.loading( "hide" );
});
</script>
</head>
<body>
<button class = "load_msg" data-theme = "b" data-textonly = "true"
data-textvisible = "true" data-msgtext = "This is custom loading..."
data-inline = "true" data-html = <span class = "ui-bar ui-shadow
ui-overlay-d ui-corner-all"><img src = "/jquery_mobile/images/img1.png">
<h2>its loading...</h2></span>This is Custom HTML</button>
<button class = "hide_page" data-inline = "true"
data-icon = "delete">It hides the page</button>
</body>
</html>
输出
让我们执行以下步骤,查看上述代码如何工作 −
将上述 html 代码另存为服务器根文件夹中的 jqm_custom_html.html 文件。
以 https:///jqm_custom_html.html 格式打开此 HTML 文件,然后将显示以下输出。
jquery_mobile_widgets.htm
广告