我有这个功能在Chrome和Firefox中运行良好,但由于某些原因它在IE中根本不起作用。
错误消息'无法获取未定义或空引用的属性'标题'
我认为它没有注册结果,但不知道为什么这只是IE的问题。
function create_the_list_item(r){
var title = $('<h3 />',{'class':'title'}).html('<span class="icon-location location">'+r.title+(r.miles?(' <span style="font-size:75%">('+r.miles+' miles away)</span> '):'' )+' </span>')
var add = $('<div />',{'class':'address left'}).html(
'<p>'+(r.address_line_1+'<br/> ' ) +
(r.address_line_2?(r.address_line_2+'<br/> '):'' ) +
(r.county?(r.county + '<br/> '):'') +
(r.country?r.country + '<br/> ' :'') +
(r.post_code?r.post_code :'')+'</p>'
);
var website = $('<div />',{'class':'right'}).html(
(r.website?('<a href="http://'+r.website.replace('http://','')+'" target="_blank">Visit Website</a><br/><br/>' ):'')+
(r.website?(r.telephone_number ):'')
)
return ($('<div />',{'class': 'the_shop_list clearfix'})
.data('longitude',r.longitude)
.data('latitude',r.latitude)
.data('title',r.title)
.data('tel',r.telephone_number)
.data('website',r.website)
.append(title).append(add).append(website)
)
}
答案 0 :(得分:0)
根据您提供的内容,错误'无法获取未定义或空引用的属性'标题'可能是指您尝试传递的对象'r ”。设置'title'变量时,对'r'的第一个引用是r.title。
'r'未被定义或创建或传递给* create_the_list_item *,正如您所期望的那样。
他们使用它的方式应该如下:
r = { title : 'my title',
county: 'my county'}
答案 1 :(得分:0)
这意味着您的r
对象可能为空,因此请追溯您的代码并console.log()
查看正在发生的事情。
如果您尝试:
function create_the_list_item(r){
console.log(r)
var title = $('<h3 />',{'class':'title'}).html('<span class="icon-location location">'+r.title+(r.miles?(' <span style="font-size:75%">('+r.miles+' miles away)</span> '):'' )+' </span>')
......
}
它会说类似undefined或null:
所以这可能就是你传递对象或任何关键字冲突的方式或者那种性质的东西。