我有一个脚本,假设您在单击复选框时显示隐藏的<div>
。我似乎无法弄清楚为什么该部分不会显示。以下是我的剧本......
以下是 JSfiddle 要查看复选框向下滚动到“添加配偶”的位置,该部分将隐藏在那里。
$.appicant.applicants();
$('#spouse').live('click', function () {
alert('s');
if ($(this).is(':checked')) {
$('.spouse-content').slideDown();
} else {
$('.spouse-content').slideUp();
}
});
答案 0 :(得分:1)
您应该使用 on()
,因为 live()
方法在jQuery版本1.7+中已弃用,并已在1.9 +中删除
$.appicant.applicants();
$('#spouse').on('click', function () {
alert('s');
if ($(this).is(':checked')) {
$('.spouse-content').slideDown();
} else {
$('.spouse-content').slideUp();
}
});
正如,@ KevinJantzer所说,行$.appicant.applicants();
答案 1 :(得分:1)
答案 2 :(得分:0)
live()
开始, 1.9
为removed。由于您已包含jQuery 1.10.1
,因此您需要使用 on() :
$('#spouse').on('click', function () {
alert('s');
if ($(this).is(':checked')) {
$('.spouse-content').slideDown();
} else {
$('.spouse-content').slideUp();
}
});
此外,您还没有包含导致此错误的applicants
插件:
Cannot call method 'applicants' of undefined
答案 3 :(得分:0)
$.applicant.applicants();
正在抛出错误。修复此问题,其余代码正常运行。另外,使用“on”代替已弃用的“live”。