我正在处理项目的问题..我之前的程序员使用了jquery 1.4.4,现在我已将其更新为1.10.2设计师使用bootstrap的原因..
但是当我在1.10.2中运行它时,在1.4.4中工作的一个对象没有在1.10.2中显示
这是1.10.2中没有显示的脚本 var interests = new Array();
$(document).ready(function () {
InitInterestPreferencesDialogs();
$(".Interest").live('click', function () {
$(".SelectedInterest").removeClass("SelectedInterest");
AddInterest(this.id);
});
jQuery.ajax({ type: "POST",
url: "/Bubble/MyInterests",
dataType: "json",
traditional: true,
success: function (data) {
$("#interestContainer").empty();
$("#interestTemplate").render(data).appendTo("#interestContainer");
RefreshPage();
}
});
});
<div id="interestouter">
<div id="interestContainer"></div>
</div>
<script id="interestTemplate" type="text/html">
<div id="{{= Id}}" icon="{{= Icon}}" class="{{= CssClass}}">
<div class="interesticon {{= Icon}}" title="{{= Name}}">
</div>
{{= Name}}
</div>
</script>
任何人都可以看到我的问题在哪里..唯一改变的是使用jquery版本1.10.2 insted of 1.4.4
答案 0 :(得分:1)
根据jQuery文档:
“从jQuery 1.7开始,不推荐使用.live()方法。使用.on()附加事件处理程序。旧版本jQuery的用户应优先使用.delegate(),而不是.live()。” / p>
所以这个
$(".Interest").live('click', function () {
$(".SelectedInterest").removeClass("SelectedInterest");
AddInterest(this.id);
});
应该替换为
$(".Interest").on('click', function () {
$(".SelectedInterest").removeClass("SelectedInterest");
AddInterest(this.id);
});