admin管理员组文章数量:1391981
This code is a simple function call:
<input type="submit" name="_eventId_load" onclick="toLoad('2012\9\27\15\2012-09-27T15-05-59-512.00638.eml');" value="Load"/>
This is what I receive in the js function:
function toLoad(path) {
document.getElementById("emailPath").value = escapepath);
}
Via firebug, I see that the param path
contains: 201292-09-27T15-05-59-512.00638.eml
And after the scape function: 20129%17%0D%812-09-27T15-05-59-512.00638.eml
The values are pletely different. How could I work/edit te \
before I send it to the js function?
Thanks in advance.
EDIT
This is the solution:
<input id="filePath-${status.index}" type="hidden" value="${file.path}"/>
<input type="submit" onclick="toLoad('${status.index}'" value="Load"/>
These inputs are inside a form, each element is a file. I need ${status.index}
to know which file I want to load. ${file.path}
contains the path I want to replace.
function toLoad(index) {
var emailPath = document.getElementById("filePath-" + index).value.replace(/\\/g,"\\\\");
document.getElementById("emailPath").value = emailPath;
}
The correct input will be included in a div, so I can use it for the final functionallity.
Thanks for your answers!
This code is a simple function call:
<input type="submit" name="_eventId_load" onclick="toLoad('2012\9\27\15\2012-09-27T15-05-59-512.00638.eml');" value="Load"/>
This is what I receive in the js function:
function toLoad(path) {
document.getElementById("emailPath").value = escapepath);
}
Via firebug, I see that the param path
contains: 201292-09-27T15-05-59-512.00638.eml
And after the scape function: 20129%17%0D%812-09-27T15-05-59-512.00638.eml
The values are pletely different. How could I work/edit te \
before I send it to the js function?
Thanks in advance.
EDIT
This is the solution:
<input id="filePath-${status.index}" type="hidden" value="${file.path}"/>
<input type="submit" onclick="toLoad('${status.index}'" value="Load"/>
These inputs are inside a form, each element is a file. I need ${status.index}
to know which file I want to load. ${file.path}
contains the path I want to replace.
function toLoad(index) {
var emailPath = document.getElementById("filePath-" + index).value.replace(/\\/g,"\\\\");
document.getElementById("emailPath").value = emailPath;
}
The correct input will be included in a div, so I can use it for the final functionallity.
Thanks for your answers!
Share Improve this question edited Sep 28, 2012 at 9:19 Blanca Hdez asked Sep 28, 2012 at 7:59 Blanca HdezBlanca Hdez 3,56319 gold badges72 silver badges95 bronze badges 2- toLoad != setAttachmentToLoad – Barmar Commented Sep 28, 2012 at 8:15
- That was a typing error when I wrote the question. In my code it has the same name – Blanca Hdez Commented Sep 28, 2012 at 8:18
3 Answers
Reset to default 3The \
is an escape character and therefore needs to be duplicated to bee a literal \
, that is, substitute all \
symbols with \\
and retry.
See Javascript - Replacing the escape character in a string literal
\
is reserved as an escape character in Javascript for special characters.
http://www.javascriptkit./jsref/escapesequence.shtml
Escaping \
itself happens with two \\
Use escape and unescape functions The unescape() function decodes an encoded string. http://www.w3schools./jsref/jsref_unescape.asp
本文标签: javascriptPass a path as a param to a JS functionStack Overflow
版权声明:本文标题:javascript - Pass a path as a param to a JS function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744743356a2622741.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论