JQuery Mobile trigger('create') 命令不起作用 [英] JQuery Mobile trigger('create') command not working

查看:30
本文介绍了JQuery Mobile trigger('create') 命令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JQuery Mobile 今晚让我哭了.我正在尝试构建自定义控件,这样我就不会在我的应用程序中重复某些元素,这让我很难受.具体来说,我在 HTML 文件中有以下内容:

<a href="index.html" data-icon="back" style="margin-top:5px" data-theme="b">Back</a><div style="text-align: center; padding-top: 5px; padding-bottom: 3px"><img src="../images/logo.png" ></div><a href="index.html" data-icon="home" style="margin-top:5px" data-theme="b">首页</a>

在我的主文件中,我基本上在做:

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script><script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script><div data-role="page" id="test-console" data-theme="m"><div id="me-header"></div><脚本>$.get('header.html', 函数 (retData) {$('me-header').html(retData).trigger('create');});

问题来了 - 标题的呈现方式与我将 header.html 的内容直接粘贴到 JQM 页面时的呈现方式不同.感觉就像 trigger('create') 没有做任何事情.

有什么想法吗?我已经烧了大约三个小时,并且像 http://jquerymobiledictionary.pl/faq.html 这样的教程似乎没有应用..

解决方案

我相信我已经找到了可用的最佳"答案.简而言之,'header' 和 'footer' 类型的数据角色元素不是标准的小部件.它们是某种混合结构.我通过浏览 JQueryMobile 的源代码发现了这一点.它们没有创建"方法,因此无法调用.

我的解决方法是直接将类应用到我的代码中,而不是期望小部件为我做这件事.不理想,但效果很好.

JQuery Mobile is making my cry tonight. I'm trying to build custom controls so I don't repeat certain elements through my app, and it's giving me a hard time. Specifically, I have the following in an HTML file:

<div id="custom-header" data-role="header" data-position="inline" data-theme="f">
    <a href="index.html" data-icon="back" style="margin-top:5px" data-theme="b">Back</a>
    <div style="text-align: center; padding-top: 5px; padding-bottom: 3px"><img src="../images/logo.png" ></div>
    <a href="index.html" data-icon="home" style="margin-top:5px" data-theme="b">Home</a>
</div>

In my main file I'm essentially doing:

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>        
<div data-role="page" id="test-console" data-theme="m">

    <div id="me-header"></div>

    <script>

        $.get('header.html', function (retData) {
            $('me-header').html(retData).trigger('create');
        });

     </script>

</div>

So here's the problem - The header doesn't render the same as it does as when I paste the contents of header.html directly into my JQM page. It almost feels like trigger('create') isn't doing anything.

Any ideas? I've burned about three hours and tutorials like http://jquerymobiledictionary.pl/faq.html don't seem to be applying..

解决方案

I believe I've found the 'best' answer available. In short, the 'header' and 'footer' type data-role elements are not standard widgets. They are some sort of hybrid construct. I found this out by just going through the source code of JQueryMobile. They don't have a 'create' method, so it can't be called.

My workaround was to just apply the classes directly to my code, instead of expecting the widget to do it for me. Not ideal, but it works well enough.

这篇关于JQuery Mobile trigger('create') 命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆