将动态生成的值从 javascript 函数发送到另一个 javascript 函数
我的网站项目还遇到另一个困难。好吧,这是我的问题...
<script>
function getTopArtist(){
if (window.XMLHttpRequest){
topartist = new XMLHttpRequest();
}
else{
topartist = new ActiveXObject("Microsoft.XMLHTTP");
}
topartist.onreadystatechange=function(){
try{
if (topartist.readyState==4 && topartist.status==200){
var ArtistDetails = topartist.responseXML.documentElement.getElementsByTagName("artist");
for(i=0;i<=2;i++){
myartistname = ArtistDetails[i].getElementsByTagName('name')[0].firstChild.nodeValue;
alert(myartistname)
document.getElementById('topartistdiv').innerHTML+='<a href="javascript:getAlbums(this is the proble here);">Albums</a>';
}
}
catch(er){
alert("Oops something went wrong!");
}
}
topartist.open("GET","http://localhost/test/topartist.php",true);
topartist.send(null);
}
</script>
我的问题出现在第 17 行,当时我试图将艺术家姓名放在括号内,然后我可以将它们发送到另一个函数。假设它提醒 Beyonce
我希望链接是这样的。
javascript:getAlbums('Beyonce');
我猜这与特殊字符有关,但我无法弄清楚。任何帮助将不胜感激。
I'm having another difficulty with my website project. Ok here is my problem...
<script>
function getTopArtist(){
if (window.XMLHttpRequest){
topartist = new XMLHttpRequest();
}
else{
topartist = new ActiveXObject("Microsoft.XMLHTTP");
}
topartist.onreadystatechange=function(){
try{
if (topartist.readyState==4 && topartist.status==200){
var ArtistDetails = topartist.responseXML.documentElement.getElementsByTagName("artist");
for(i=0;i<=2;i++){
myartistname = ArtistDetails[i].getElementsByTagName('name')[0].firstChild.nodeValue;
alert(myartistname)
document.getElementById('topartistdiv').innerHTML+='<a href="javascript:getAlbums(this is the proble here);">Albums</a>';
}
}
catch(er){
alert("Oops something went wrong!");
}
}
topartist.open("GET","http://localhost/test/topartist.php",true);
topartist.send(null);
}
</script>
My problem is on line 17 when I'm trying to put the artist name inside the brackets to then I can send them to another function. So let's say it alerts Beyonce
I want the link to be like this.
javascript:getAlbums('Beyonce');
I guess it has something to do with special characters but I can't figure it out. Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要引用该字符串,并且您已使用
'
作为 JavaScript 字符串,使用"
作为 HTML 属性字符串。使用转义单引号
\'< /代码>。
You need to quote the string, and you have already used
'
for the JavaScript string and"
for the HTML attribute string.Use escaped single quote,
\'
.