我现在有这个添加JavaScript变量HREF
destDiv.append("<td><a href="+value.FileLocation+">Download Here</a></td>")
但其实我是想给value.filelocation URL编码到我的下载脚本getsonginfo.php
我现在有这个添加JavaScript变量HREF
destDiv.append("<td><a href="+value.FileLocation+">Download Here</a></td>")
但其实我是想给value.filelocation URL编码到我的下载脚本getsonginfo.php
如果我理解正确你的问题,所有的你想要做的是以下几点:
destDiv.append("<td><a href='getsonginfo.php?url="+encodeURIComponent(value.FileLocation)+"'>Download Here</a></td>")
的encodeURIComponent
将正确处理编码value.FileLocation
,并在href需要'
左右,以便正确解析(否则encodeURIComponent
是毫无意义的)。
你从哪里得到'getsonginfo.php?url ='? 0_o – SeinopSys 2014-08-27 15:09:59
而且,你是从哪里得到了它需要围绕它的单引号的想法?不对。 – 2014-08-27 15:10:29
@ DJDavid98“到我的下载脚本getsonginfo.php”'url ='部分是我的即兴创作,但是使用PHP是最有可能的构造。 – user2908232 2014-08-27 15:11:01
那么使用'encodeURIComponent'并对其进行编码? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent – 2014-08-27 15:08:29
这里是答案训练。你有没有尝试研究“url编码值javascript”? – 2014-08-27 15:09:02
[How to encode URL in JavaScript and PHP?](http://stackoverflow.com/questions/2332413/how-to-encode-url-in-javascript-and-php) – 2014-08-27 15:09:30