开发者

Javascript slash is missing when called in argument

I am passing a path as an argument in a Javas开发者_Go百科cript. For example I am passing a path as c:\my documents\user\aa.jpg when registering Javascript in client side.

When calling this in a function say, function js(d) then the slash goes missing, hence the value of 'd' becomes c:mydocumentsuseraa.jpg

What to do?


Have you escaped your backslashes ?

alert( 'c:\\my documents\\user\\aa.jpg' );


pass it like this:

c:\\my documents\\user\\aa.jpg

you need to escape the slash char. thanks

You should always pass the slash char which has special meaning for example, you can use it to specify new lines like \n, tabs \t, etc. So you should escape it with another slash char to make it come single slash char.


You said when registering javascript in client side.

I assume you are doing this in the code behind as you have tagged asp.net. So I think you would need to use @ before the string while registering the scipt.

Like @"c:\abc\xyz.jpg"

OR you can go by the method Sarfraz mentiond. i.e. pass the string as "c:\\abc\\xyz.jpg"

I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜