我現在有這個添加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