我在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