Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有包含反斜杠的变量的Javascript window.prompt_Javascript_Jquery_Prompt_Backslash - Fatal编程技术网

带有包含反斜杠的变量的Javascript window.prompt

带有包含反斜杠的变量的Javascript window.prompt,javascript,jquery,prompt,backslash,Javascript,Jquery,Prompt,Backslash,我有一个包含超链接的页面(自然),这些超链接是从SQL表构造的,但有些超链接实际上是网络资源(即.\server\path)。对于那些,我设置了一个jQuery语句来查找它们并替换那些”; } 提示有效,但文本区域看起来与此完全相同。ext使用两个反斜杠,而不是一个:\\server\\path JavaScript字符串/正则表达式中的反斜杠具有转义字符的特殊含义: var stringWithNewLine = "This doesn't work"; //Error var strin

我有一个包含超链接的页面(自然),这些超链接是从SQL表构造的,但有些超链接实际上是网络资源(即.\server\path)。对于那些,我设置了一个jQuery语句来查找它们并替换那些
”;
}

提示有效,但文本区域看起来与此完全相同。ext

使用两个反斜杠,而不是一个:
\\server\\path

JavaScript字符串/正则表达式中的反斜杠具有转义字符的特殊含义:

var stringWithNewLine = "This
doesn't work"; //Error

var stringWithNewLine = "This\ndoes work"; //Escaped new-line feed.

mysql\u real\u escape\u string()
是您的解决方案

echo mysql_real_escape_string("hello\world");
输出

hello\\world

因此,在将服务器值传递回客户端之前,请先转义它们。

我刚刚想到了一个简单的解决方案,可以在从SQL加载URL值后“转义”URL值。这样,我可以有选择地针对要转义的内容,并保持正常的http URL不变:

else if (($link.length > 0) && ($link.substring(0, 4) != "http")) {
            $linkescaped = $link.replace(/\\/g, "\\\\");
            $('.filter', $this.closest('tr')).after("<span><a href='#link' onclick='window.prompt(\"This resource is located on a network drive and is not accessible via the web browser. Please copy the link and paste into Windows Explorer.\",\""+$linkescaped+"\");'></a></span>");
        }
else if($link.length>0)和($link.substring(0,4)!=“http”)){
$linkescaped=$link.replace(/\\/g,“\\\\”);
$('.filter',$this.closest('tr')。在(“”)之后;
}

这并不能完全回答我的问题。我知道我需要两个反斜杠,但问题是如何将它们转换为从SQL表传递的字符串。我提出了一个解决方案,但感谢您的回答。如果您的解决方案与我的回答完全不同,请将其作为新的答复发布并接受。
else if (($link.length > 0) && ($link.substring(0, 4) != "http")) {
            $linkescaped = $link.replace(/\\/g, "\\\\");
            $('.filter', $this.closest('tr')).after("<span><a href='#link' onclick='window.prompt(\"This resource is located on a network drive and is not accessible via the web browser. Please copy the link and paste into Windows Explorer.\",\""+$linkescaped+"\");'></a></span>");
        }