我在JavaScript中有一個變量,其中包含圖像的目錄。 我想把它傳遞給href 如何做到這一點?將變量從javascript傳遞給href
function OpenNewWindow(n, width, height)
{
if(navigator.appName == "Microsoft Internet Explorer"){
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
xhttp.open("GET","http://www.multimediaprof.com/test/emp2.xml",false);
}
else if(navigator.appName == "Netscape"){
xhttp=new XMLHttpRequest();
// alert("step 1");
xhttp.open("GET","xml/emp2.xml",false);
}
xhttp.send("");
xmlDoc=xhttp.responseXML;
var imageName = xmlDoc.documentElement.childNodes[n].textContent;
TestP[n] = imageName;
alert(TestP[n]);
var img = document.createElement('img');
img.src = "pic/" + imageName;
alert(img.src);
return img.src;
<li><a href="javascript:OpenNewWindow(1,000,000);alert('clicked!');" rel="shadowbox" ">Part 0</a></li>
變量img.src包含路徑,我想將它傳遞給HREF
請提供一些您的代碼。 – Oyeme 2012-03-22 07:10:09
將你的接受程度提高到綠色水平 – 2012-03-22 07:11:17
你[第一次問它]是什麼問題(http://stackoverflow.com/questions/9804790/passing-javascript-variable-to-href)? – Neysor 2012-03-22 07:13:18