我正在嘗試運行兩個不同的函數,它們執行兩個單獨的事情。當一個div被點擊時,兩者都需要運行。 div是在JavaScript的innerHTML函數中生成的。使用.innerHTML發送參數到JS函數
這是第二次運行的方法。它需要一個參數,然後在頁面上生成一個div。
//Display larger image:
function furtherDetails(mainImage){
var moreInfo = document.getElementById('divpropertyInfo');
moreInfo.innerHTML = '<div id="propInfoDisplay">' +
'<img id="image" src="'+mainImage+'" alt="Main Image" />' +
'</div>';
}
這是一個運行該函數的代碼:
//Create the property div:
function createPropertyDiv(mainImage, bedrooms, bathrooms, parkings, price, address, latitude, longitude){
var propertyDiv = document.getElementById('divsearchResults');
propertyDiv.innerHTML += '<div id="divResults" onclick="showMap('+latitude+','+longitude+');furtherDetails('+mainImage+');">' +
'<img id="mainImage" src="' + mainImage +'" alt="Main Image" />' +
'<p id="numBedrooms">'+ bedrooms +'</p>' +
'<img id="bedroomsImage" src="/images/bedrooms.png" />' +
'<p id="numBathrooms">'+ bathrooms +'</p>' +
'<img id="bathroomsImage" src="/images/bathrooms.png" />' +
'<p id="numParking">'+ parkings +'</p>' +
'<img id="parkingImage" src="/images/carspots.png" />' +
'<p id="Price">'+ price +'</p>' +
'<p id="addressHeading">Address: </p>' +
'<p id="Address">' + address + '</p>' +
'</div>';
}
我收到錯誤:
Uncaught SyntaxError: missing) after argument list
當你得到這個錯誤?你點擊的時間? – Farsay
@Christopher我不認爲這兩個函數的錯誤是否可以共享一個顯示錯誤的工作片段,如果可能的話JSFiddle? –
檢查你的函數對'('&')' –