为什么我收到jQuery错误“类型错误:$(..).在以下场景中,Live 不是一个函数
Why I'm getting the jQuery error "TypeError: $(...).live is not a function " in following scenario?
>实际上,我正在尝试对一个文本字段实现自动完成功能,但出现上述错误,无法理解为什么会出现此错误。你能帮我解决这个错误吗?供您参考,我在下面提供了所有必要的代码:
报告-学生-结果.tpl
<link rel="stylesheet" type="text/css" href="{$control_css_url}ui-lightness/jquery-ui-1.10.3.custom.css">
<link rel="stylesheet" type="text/css" href="{$control_css_url}autocomplete.css">
<label>Name</label>
<div class="form-element" id="friends">
<input type="text" class="" name="user_name" id="user_name" value="{$user_name}" />
</div>
<script language="javascript" type="text/javascript">
$(function(){
var class_id = $('#class_id').val();
var section_id = $('#section_id').val();
//attach autocomplete
$("#user_name").autocomplete({
//define callback to format results
source: function(req, add){
//pass request to server
$.getJSON("report_student_result.php?callback=?op=get_student_names&class_id="+class_id+"§ion_id="+section_id, req, function(data) {
//create array for response objects
var suggestions = [];
//process response
$.each(data, function(i, val){
suggestions.push(val.name);
});
//pass array to callback
add(suggestions);
});
},
//define select handler
select: function(e, ui) {
//create formatted friend
var friend = ui.item.value,
span = $("<span>").text(friend),
a = $("<a>").addClass("remove").attr({
href: "javascript:",
title: "Remove " + friend
}).text("x").appendTo(span);
//add friend to friend div
span.insertBefore("#user_name");
},
//define select handler
change: function() {
//prevent 'to' field being updated and correct position
$("#user_name").val("").css("top", 2);
}
});
//add click handler to friends div
$("#friends").click(function(){
//focus 'to' field
$("#user_name").focus();
});
//add live handler for clicks on remove links
$(".remove", document.getElementById("friends")).live("click", function(){
//remove current friend
$(this).parent().remove();
//correct 'to' field position
if($("#friends span").length === 0) {
$("#user_name").css("top", 0);
}
});
});
</script>
请帮助我解决此错误。提前谢谢。
live()
自 1.9 版以来已被删除,自 1.7 版起已弃用:
你会想要on()
现在的日子
$('#friends').on("click", ".remove", document.getElementById("friends"), function(){
其中 #friends
在 DOM 上可用 就绪。不能在动态加载的元素上绑定on()
。
您可以使用
.on()
而不是.live()
(在Jquery 1.7之后已弃用(
$(document).on('event', 'selector', function() {});
替换.live()
.
例如:
$( document ).on( "click", "#elementId ", function(){ alert( "Do here what you want!" ); // jQuery1.7+ });
Live(( 自 1.9 以来已从 jquery 中删除。 请使用on
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 使用Facebook live API创建实时视频对象时的隐私设置
- Ajax Live搜索发布到Laravel视图
- 我如何修复包含在captcha的addthis中的错误
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 节点是否需要模块传递带有方括号的arg?这是个错误吗
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- CKFinder 3为所选文件返回错误的URL
- 同位素库错误:未捕获错误无布局模式包装生产线8
- 铬:“;未捕获的语法错误:意外的标记:"
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 相位器状态未捕获参考错误
- /undefined在我的404错误日志中多次出现
- Javascript未捕获语法错误意外的标识符错误
- 类型错误: $(..).Live 不是 MVC 中的函数
- 为什么我收到jQuery错误“类型错误:$(..).在以下场景中,Live 不是一个函数