[英]How can I use an Anchor Tag in a .Append Statement Jquery
我陷入了需要在附加的<li>
附加锚标签链接的情况,但是我不知道如何开始
这是我的代码:
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
function codeAddress() {
infoBubble = new InfoBubble({
map: map,
shadowStyle: 0,
padding: 10,
borderRadius: 10,
arrowSize: 15,
maxWidth: 300,
borderWidth: 1,
borderColor: '#ccc',
arrowPosition: 50,
arrowStyle: 0
});
$.getJSON('/Dashboard/LoadWorkerList', function (address) {
$.each(address, function () {
var currVal = this["AddressLine1"];
var Name = this["Name"];
var Gender = this["Gender"];
var Bdate = this["Birthdate"];
var ID = this["Worker_ID"];
geocoder.geocode({ 'address': currVal }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
icon: iconBase + 'man.png',
position: results[0].geometry.location,
title: currVal
})
$('#places').append($('<li>')
.text(currVal)
.data('location', results[0].geometry.location));
google.maps.event.addListener(map, 'bounds_changed', function () {
$('#places li').css('display', function () {
return (map.getBounds().contains($(this).data('location')))
? ''
: 'none';
});
});
function myclick(i) {
google.maps.event.trigger(address[i], "click");
}
//mgr = new MarkerManager(map);
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infoBubble.removeTab(0);
infoBubble.addTab(Name, "Name: " + Name + "<br> Address: " + currVal + "<br> Gender: " + Gender + "<br> Birthdate: " + Bdate + "<br><br>" + '<center><a href="/Worker/WorkerDetails?workerId=' + ID + '">View Profile</a></center>');
infoBubble.open(map, marker);
}
})(marker, currVal));
address.push(marker);
}
else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
setTimeout(codeAddress, 2000);
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
});
google.maps.event.trigger(map, 'bounds_changed');
});
}
但是我尝试更改此方法但不起作用
$('#places').append($('<li>')
.wrap('<a href="javascript:myclick(' + (address.length - 1) + ')">' + location + '</a><br>')
.data('location', results[0].geometry.location));
它没有显示在列表中。 。 提前致谢!
不确定要实现的目标,但是内联事件处理程序不是可行的方法
也许你应该尝试
var j =i;
var link = $('<a href="#">linkTextHere</a>')
.data('location', results[0].geometry.location);
$('#places').append($('<li/>').append(link));
link.on('click', function(event){
event.preventDefault();
google.maps.event.trigger(address[j], "click");
}
);
代替 :
$('#places').append($('<li>')
.wrap('<a href="javascript:myclick(' + (address.length - 1) + ')">' + location + '</a><br>')
.data('location', results[0].geometry.location));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.