Arc*_*nic 5 internet-explorer-9 jquery-1.8
以下适用于IE 9.0.8以外的所有浏览器.它使用ajax请求在div中加载调查表单.
$('.tab-content').on('click', '.show_survey_form', function(e) {
e.preventDefault()
target = $(this).attr("data-target")
my_href = $(this).attr("href")
console.log("load: " + target + " target: " + my_href)
// load: #survey_response_form_33 target: /surveys/33/survey_responses/edit_multiple
// Don't make a request unless the form is opening.
if ($(this).hasClass('collapsed')) {
console.log("Making request!")
//$(target).load(my_href)
$(this).html(closeSurveyForm) // Just changes the language on the button
} else {
$(this).html(respondToSurvey) // Just changes the language on the button
}
}
Run Code Online (Sandbox Code Playgroud)
.load在调试期间被注释掉.IE在这种情况下使用.hasClass似乎有问题.它在其他地方使用没有问题.
真正奇怪的是,当我打开开发工具窗口时,它开始工作.它在此之前始终不起作用,并且在击中F12之后始终如一.
其他问题表明,当类包含\ r \ncchar时,hasClass方法不起作用,但这不是这种情况.我正在使用jQuery 1.8.3.
更新:将href更改为"#"并将URL写入数据加载无效.仍然适用于除IE 9.0.8之外的所有浏览器.
Spu*_*ley 12
这与jQuery或者无关hasClass().这完全取决于你的使用console.log().
重要的是要知道console在打开F12开发工具窗口之前IE不会定义对象.
这意味着在打开它之前,console调用将抛出javascript"object undefined"错误.这将使它看起来周围的代码不起作用,但实际上只是控制台对象丢失的事实.
您可能在其他较旧的浏览器中具有类似的效果,但大多数当前的浏览器版本不会这样做 - 它们会console立即定义对象,无论开发工具是否打开.IE是唯一的例外.
您可以通过(a)不使用来解决这个问题,console除非您实际调试并打开开发工具,或者(b)if(console)为您的所有console呼叫添加一个检查.这样可以防止错误.
更多信息:为什么JavaScript只在IE中打开开发人员工具后才能工作?
| 归档时间: |
|
| 查看次数: |
4737 次 |
| 最近记录: |