Javascript 脚本在IE浏览器中不工作
我正在使用“单击事件”功能将用户的每个活动保存到数据库中,但脚本在IE浏览器中不起作用。请建议我解决这个问题Javascript 脚本在IE浏览器中不工作,javascript,jquery,Javascript,Jquery,我正在使用“单击事件”功能将用户的每个活动保存到数据库中,但脚本在IE浏览器中不起作用。请建议我解决这个问题 document.addEventListener("click", function(event){ var url_path = window.location.pathname; var type = event.target.type var name = event.target.name var old_value = event.
document.addEventListener("click", function(event){
var url_path = window.location.pathname;
var type = event.target.type
var name = event.target.name
var old_value = event.target.value
if(name === undefined || name == null || name.length <= 0)
{
}
else
{
$.ajax({type: "POST",
url: "application/record_user_activity",
data: { click_obj_type:type, click_obj_name:name,click_obj_old_value: old_value},
success:function(result){
// alert("success")
}});
}
});
document.addEventListener(“单击”,函数(事件){
var url_path=window.location.pathname;
变量类型=event.target.type
var name=event.target.name
var old_value=event.target.value
如果IE的(name==undefined | | name==null | | | name.length,请使用attachEvent
而不是addEventListener
,因为IE<9中不支持addEventListener
还请注意,在IE>11中,attachEvent
不受支持
参考文献
所以,尝试使用
if(window.addEventListener){
//code
}
else if(window.attachEvent){
// code
}
IE上有任何功能吗?addEventListener
受支持,因为IE 9: