2010-06-28 51 views
0

我试图Concat的查询值转换为链接Javascript字符串问题

wwww.test /视频(查询值)“ FLV的”

altought我想我做错了什么。

function doSomething() { 

     var test = new StringBuilderEx(); 
     var a = querySt("number"); 
     test.append("<h1>test</h1> "); 
     test.append("<a "); 
     test.append("href=\"http://test.com/video\"" + a + ".flv\" "); 
     test.append("Style =\"display:block;width:425px;height:300px;\" "); 
     test.append("id=\"player\" "); 
     test.append("</a> "); 
     test.append("<script language=\"JavaScript\" "); 
     test.append("> "); 
     test.append("flowplayer(\"player\" "); 
     test.append(", \"flowplayer-3.2.2.swf\" "); 
     test.append("); <\/script>"); 
     return test.toString() 
    } 

最后我得到的是一个链接test.com /视频和传递的价值。该StringBuilderEx是JS脚本和queryST是

function querySt(ji) { 
     hu = window.location.search.substring(1); 
     gy = hu.split("&"); 
     for (i = 0; i < gy.length; i++) { 
      ft = gy[i].split("="); 
      if (ft[0] == ji) { 
       return ft[1]; 
      } 
     } 
    } 

因此,这将是真棒,如果我了解什么我没有得到 其中1是查询号码。 HREF = “http://test.com/video1.flv”

回答

2
test.append("href=\"http://test.com/video\"" + a + ".flv\" "); 

你有外来\"那里。

test.append("href=\"http://test.com/video" + a + ".flv\" "); 

而且缺少>

test.append("id=\"player\" "); 

应该

test.append("id=\"player\">"); 

而且,你的链接没有任何内容上

test.append("</a> "); 

单击要

test.append("Click me!</a> "); 
+0

那么链接打算没有内容,但你是正确的/ :)谢谢你 – Jonathan 2010-06-28 01:46:04