-1
在這裏,我有一個contentStr HTML代碼,我必須在jQuery的對話框(叫)是這樣的:jQuery的對話框 - 按鈕,在內容與功能
$(contentStr).dialog({
modal:true
});
但問題是becouse我到contentStr一個按鈕,HTML和我需要運行的點擊功能,所以我嘗試:
contentStr += '<button'+ onclick=addContent(); +'>Add to timeline</button>';
和:
contentStr += '<button onclick="addContent()">Add to timeline</button>';
,但是這不會工作。我怎樣才能解決我的問題,並添加按鈕HTML到contentStr和運行功能addContent()點擊?
UPDATE:
google.maps.event.addListener(marker,'click',function(){
service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
//class m_tooltip
var contentStr = '<div><h5>'+place.name+'</h5><p>'+place.formatted_address+'</p>';
if (!!place.photos) contentStr += '<img src='+place.photos[0].getUrl({ 'maxWidth': 500, 'maxHeight': 500 })+'></img>';
if (!!place.formatted_phone_number) contentStr += '<br>'+place.formatted_phone_number;
if (!!place.website) contentStr += '<br><a target="_blank" href="'+place.website+'">'+place.website+'</a>';
//if (!!place.opening_hours.periods[1].open.time) contentStr += '<br>'+place.opening_hours.periods[1].open.time;
if (place.reviews && place.reviews.length) for(var i=0;i<place.reviews.length;i++){
contentStr += '<br>'+ place.reviews[i].text+ '</br>';
}
contentStr += '<p>'+distanca/1000+'km</p>';
//var pvreme = vreme/60;
contentStr += '<p>'+vreme+'</p>';
var cons = google.maps.geometry.spherical.computeDistanceBetween(startMarkerPosition,endMarkerPosition);
var mnozilac = distanca/cons;
var stop = place.geometry.location;
var between = google.maps.geometry.spherical.computeDistanceBetween(startMarkerPosition,stop)/1000*mnozilac;
var time = between/110*60;
var time = Math.floor(time);
var zajson = formatTime(time);
contentStr += '<p>'+ parseFloat(between).toFixed(2) + 'km</p>';
contentStr += '<p>'+ formatTime(time) + '</p>';
contentStr += '<button>Add to timeline</button></div>';
//contentStr += '<div><gcse:search></gcse:search></div></div>';
$(contentStr).dialog({
modal:true
});
//contentStr += '<h5">'+place.reviews[0].text+'</h5></div>';
//ib.setContent(contentStr);
//ib.open(map,marker);
} else {
var contentStr = "<h5>No Result, status="+status+"</h5>";
//ib.setContent(contentStr);
//ib.open(map,marker);
$(contentStr).dialog();
}
});
});
我會給這個按鈕一個id並綁定/點擊事件。 – stevemarvell
我試試$('button #klik')。click(addContent()); contentStr + ='';但不工作 – drTesla