javascript - JQuery Mobile DateBox - 超过 1 个实例

标签 javascript jquery jquery-mobile

我正在使用 JQuery Mobile Datebox,因为我遇到以下问题。

我有页面 A 和页面 B。

如果我转到页面 B 并打开名为“date2”的日期选择器,然后将其关闭并单击主页链接,该链接将转到页面 A。

现在,我在页面 a,点击按钮打开日期选择器 A,称为“日期”...

问题是我两个都打开了......就好像它们都被打开了或者什么的。

关闭后如何终止日期选择器的实例?

这是页面A的相关代码:

在头部:

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

然后是表单/日期选择器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>

现在是页面B的相关代码

在页面头部:

<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>

以及表单部分:

<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>

有人有任何线索吗?

谢谢

最佳答案

如果您使用的是 jquery mobile,请勿对 jqm 使用 document.ready()。不起作用。使用类似的东西代替。 查看 jqm 演示以获取完整的事件列表。 Demo

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

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


    });

此外,所有 js 都应该位于加载的第一个 html 中。在你的例子中,它是页面A。 很简单,因为后续页面是通过ajax加载的,里面写的js不会被执行。

关于javascript - JQuery Mobile DateBox - 超过 1 个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6090190/

相关文章:

javascript - 通过 jquery 发布多个 Facebook 帖子

javascript - jQUery 代码在 IE 中不起作用

css - 以列表格式列出地址的问题?

jquery-mobile - jQuery Mobile : about the page container ($. mobile.pageContainer)

jquery - 如何将错误消息显示回 ASP.NET MVC 页面?

jquery - JQuery Mobile 中的选项卡事件状态

javascript - Angular 2 和被动听众

javascript - "Then"Promise后没有执行

javascript - 使用 javascript 添加行时无法使用表单验证

javascript - 与有 Angular 物体比较