以下适用于除 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
}
}
.load 在调试期间被注释掉。IE 在这种情况下使用 .hasClass 似乎有问题。它在其他地方使用没有问题。
真正奇怪的是,当我打开开发工具窗口时,它就开始工作了。在此之前它始终不起作用,并且在达到 F12 后始终起作用。
其他问题表明当类包含 \r 字符时 hasClass 方法不起作用,但这里不是这种情况。我正在使用 jQuery 1.8.3。
更新:将 href 更改为“#”并将 URL 写入数据加载无效。除 IE 9.0.8 外,仍然适用于所有浏览器。