【问题标题】:0x800a138f - JavaScript runtime error: Unable to get property 'setAttribute' of undefined or null reference jquery0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用 jquery 的属性“setAttribute”
【发布时间】:2014-03-19 13:58:49
【问题描述】:

只有在尝试通过 IE 11 执行 mvc 4 应用程序时才会出现以下错误,但它在 google chrome 上运行良好。

0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用 jquery 的属性“setAttribute”

以下是发生错误的代码段。但我可以确保登录屏幕上没有数据选择器对象。一定是什么导致了问题?

    if (!Modernizr.inputtypes.date) {
$(function () {
    $("input[type='date']")
                .datepicker()
                .get(0)
                .setAttribute("type", "text");
})

}

【问题讨论】:

  • 你为什么在if 语句中调用document ready?第二个:使用这个$("input[type='date']").attr("type", "text")$("input[type='date']").prop("type", "text")
  • 另外,刚刚检查了您在 jsfiddle 中的代码,它工作正常(没有 if 语句,因为我没有定义 Modernizr 对象)。
  • 添加 prop 或 attr 除了以下消息没有任何区别:0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“prop”
  • If 被使用是因为我想在可用时使用 HTML5 日期选择器而不是 jquery。

标签: jquery asp.net asp.net-mvc internet-explorer


【解决方案1】:

使用.attr() 设置属性。 API的链接

【讨论】:

    最近更新 更多