简体   繁体   English

JQuery Mobile DateBox - 超过1个实例

[英]JQuery Mobile DateBox - more than 1 instance

I am using JQuery Mobile Datebox as I am having the following problem. 我正在使用JQuery Mobile Datebox,因为我遇到以下问题。

I have page A and page B. 我有第A页和第B页。

If I go to page B and open the date picker called "date2", then close it and click the Home page link, which goes to page A. 如果我转到页面B并打开名为“date2”的日期选择器,则关闭它并单击主页链接,该链接转到页面A.

Now, I'm in page a and I hit the button to open up date picker A, called "date" ... 现在,我在页面a,然后按下按钮打开日期选择器A,称为“日期”...

The problem is that I'm getting both opening ... it's like they are both opened or something. 问题是,我正在打开......这就像是他们都打开了什么。

How can I kill the instance of the date pickers once closed please? 如何关闭日期选择器的实例呢?

Here's the relevant code for page A: 这是第A页的相关代码:

In the head: 在头部:

<script type="text/javascript">
        $( document ).bind( "mobileinit", function(){
            $.mobile.page.prototype.options.degradeInputs.date = 'text';
        }); 
    </script>

Then the form / date picker 1: 然后表格/日期选择器1:

<form action="#" method="POST">
        <div data-role="fieldcontain" style="visibility:hidden;">
          <input value="" name="date" type="date" data-role="datebox" id="date" data-theme="a" data-options='{"mode": "calbox", "pickPageTheme": "a", "pickPageHighButtonTheme": "e", "setDateButtonLabel": "Calendar", "useDialogForceTrue": false, "useDialogForceFalse": true }'/>   


          </div>
          </form>

Now the relevant code for page B 现在是B页的相关代码

in the page head: 在页面头部:

<script type="text/javascript">
        $( document ).bind( "mobileinit", function(){
            $.mobile.page.prototype.options.degradeInputs.date = 'text';
        }); 
    </script>

<script language="javascript">
    $(document).ready(function() {

       var queryDate = $.url.param("mydate");
       $('#date2').val(queryDate);


    });

</script>

And the form part: 表格部分:

<form action="save.php" method="POST">

          <label for="date2" style="margin:10px 0px;">Event Date:</label>
          <input value="1/1/2011" name="date2" type="date" data-role="datebox" id="date2" data-theme="a" data-options='{"pickPageTheme": "a", "pickPageHighButtonTheme": "e", "setDateButtonLabel": "Add Date", "dateFormat": "dd/mm/YYYY"}'/>  

          <label for="textarea">Add:</label>
                <textarea cols="40" rows="8" name="textarea" id="textarea"></textarea>
                <input type="submit" value="Save" data-theme="a" />


          </form>

Anyone has any clues please? 有人有任何线索吗?

Thanks 谢谢

If you're using jquery mobile do not use document.ready() for jqm. 如果您正在使用jquery mobile,请不要将document.ready()用于jqm。 it will not work. 不起作用。 use something like this instead. 使用这样的东西。 check out the jqm demo for the full list of events. 查看jqm演示以获取完整的事件列表。 Demo 演示

 $(document).live('pageshow',function() {

       var queryDate = $.url.param("mydate");
       $('#date2').val(queryDate);


    });

Also all js should be in the first html that is loaded. 此外,所有js都应该在加载的第一个html中。 in your case it's page A. Simply because the subsequent page is loaded via ajax and js that is written inside will not be executed. 在你的情况下,它是页面A.只是因为后续页面是通过ajax加载的,并且内部写入的js将不会被执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM