javascript - 动态填充具有限制日期的 jQuery 移动日期框

标签 javascript jquery html attr datebox

我在使用 jQuery Mobile 的日期框插件时遇到问题。

在我的代码中,我生成了一个 ISO8601 格式的日期数组,因为这是 datebox 所需要的。

我在调用 ajax 方法并返回一些结果(响应用户输入)后生成此数组。然后我使用 jQuery .attr 函数将数据选项属性添加到我的“calbox”节点,如下所示:

<input name="mydate" id="mydate" type="date" data-role="datebox">

我的 jQuery 代码如下所示:

$("#NewPaymentPlans").attr("data-options", '{"mode": "calbox", "enableDates": ' +      DateString + ' }');

DateString 是转换为字符串的日期数组。

输出的 HTML 看起来像这样:

<input name="NewPaymentPlans" id="NewPaymentPlans" type="text" data-role="datebox" class="ui-input-text ui-body-c" readonly="readonly" data-options="{&quot;mode&quot;: &quot;calbox&quot;, &quot;enableDates&quot;: [&quot;2013-08-06&quot;, &quot;2013-08-07&quot;, &quot;2013-08-08&quot;, &quot;2013-08-09&quot;, &quot;2013-08-10&quot;, &quot;2013-08-11&quot;, &quot;2013-08-12&quot;, &quot;2013-08-13&quot;, &quot;2013-08-14&quot;, &quot;2013-08-15&quot;, &quot;2013-08-16&quot;, &quot;2013-08-17&quot;, &quot;2013-08-18&quot;, &quot;2013-08-19&quot;, &quot;2013-08-20&quot;, &quot;2013-08-21&quot;, &quot;2013-08-22&quot;, &quot;2013-08-23&quot;, &quot;2013-08-24&quot;, &quot;2013-08-25&quot;, &quot;2013-08-26&quot;, &quot;2013-08-27&quot;, &quot;2013-08-28&quot;, &quot;2013-08-29&quot;, &quot;2013-08-30&quot;, &quot;2013-08-31&quot;, &quot;2013-09-01&quot;, &quot;2013-09-02&quot;, &quot;2013-09-03&quot;, &quot;2013-09-04&quot;] }">

(& quot; 在 Chrome 显示的 HTML 中显示为双引号)。

据我所知,这应该可行。我做了一个测试,我使用了我的输出代码并填写了数据选项选项,这样页面就加载了它们并且可以正常工作。

我认为动态分配数据选项属性可能存在问题。有人知道更多吗?

编辑:已解决!

我想通了。

$("#NewPaymentPlans").data('mobileDatebox').options.enableDates = arrayofdates
$('#NewPaymentPlans').datebox('refresh');

结合这个功能:

function CreateDateArray(arrayofdates) {
var datesarray = [];
var stringofdates;
$.each(arrayofdates, function (i) {
    datesarray.push(arrayofdates[i].toISOString().substring(0, 10));
});
return datesarray

最佳答案

动态填充后尝试调用 $('#NewPaymentPlans').datebox('refresh')

关于javascript - 动态填充具有限制日期的 jQuery 移动日期框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17811032/

相关文章:

javascript - 网络扩展 : Why does the browser add a trailing slash to the requested URL?

javascript - 如何动态更新其他页面的内容

php - 使用 XHR 取消 PHP 脚本?

javascript - 如何将 $.each 循环中的结果相加?

javascript - 在jquery中使用jsonp似乎总是失败

html - skin/style dnn导航菜单的 secret 是什么

php - 强制 nginx 立即关闭连接

html - 在父 div 中排列水平 div

html - 什么是 CSS 中的内容包装器?

javascript - Jquery Drop Down Menu 允许下拉多个菜单