简体   繁体   English

这个简单的代码无法运行

[英]This simple code doesn't run

it is very simple at the first look but the variable doesn't take the string as a text I guess, I don't know why?乍一看很简单,但我猜变量不会将字符串作为文本,我不知道为什么? I am using notepad++我正在使用记事本++

 var cnextimage = "C:\\Users\\disley\\Desktop\\My Website\\image\\" ; document.write(cnextimage);

Use \\\\ for a symbol back-slash .使用\\\\作为符号back-slash \\ is a reserved symbol. \\是保留符号。 For example \\n means a line break.例如\\n表示换行。 When you write a \\ the engine waits for a special character like n .当您编写\\ ,引擎会等待像n这样的特殊character So to distinguish that you are using back-slash you need to use \\\\ for it.因此,为了区分您使用back-slash您需要使用\\\\来表示它。

 var cnextimage = "C:\\\\Users\\\\disley\\\\Desktop\\\\My Website\\\\image\\\\"; document.write(cnextimage);

You need to explicitly escape the slashes using a double-slash \\\\ as a normal slash is a reserved character:您需要使用双斜杠\\\\显式转义斜杠,因为普通斜杠是保留字符:

var cnextimage = "C:\\Users\\disley\\Desktop\\My Website\\image\\";
document.write(cnextimage);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM