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

问题描述

JQuery Mobile今晚正在呐喊。我正在尝试构建自定义控件,所以我不会通过我的应用重复某些元素,这给我一个困难的时刻。具体来说,我在HTML文件中有以下内容:

 < div id =custom-headerdata-role = headerdata-position =inlinedata-theme =f> 
< a href =index.htmldata-icon =backstyle =margin-top:5pxdata-theme =b>返回< / a>
< div style =text-align:center; padding-top:5px; padding-bottom:3px>< img src =../ images / logo.png> DIV>
< a href =index.htmldata-icon =homestyle =margin-top:5pxdata-theme =b> Home< / a>
< / div>

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

 < 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 =pageid =test-consoledata-theme =m>

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

< script>

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

< / script>

< / div>

所以这里的问题 - 标题不像在粘贴header.html的内容直接插入到我的JQM页面中。几乎感觉像触发器('创建')没有做任何事情。



任何想法?我烧了大约三个小时,像这样的教程似乎不适用

解决方案

我相信我找到了最好的答案。简而言之,标题和页脚类型的数据角色元素不是标准小部件。他们是某种混合体。我发现这只是通过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触发器('create')命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 11:28