Php 反斜杠从文件名中消失
这是我的代码:Php 反斜杠从文件名中消失,php,javascript,backslash,slash,Php,Javascript,Backslash,Slash,这是我的代码: <script> document.getElementById(div').innerHTML = '<a href="javascript:void(0);" onclick="openPhpFile (\'asdasD\\Asdeqw.txt\');">efff</a>'; </script> document.getElementById(div').innerHTML=''; 当openPhpFile函数运行时,我会
<script>
document.getElementById(div').innerHTML = '<a href="javascript:void(0);" onclick="openPhpFile (\'asdasD\\Asdeqw.txt\');">efff</a>';
</script>
document.getElementById(div').innerHTML='';
当
openPhpFile
函数运行时,我会提醒文件名,\字符会消失,即使它们是两倍的addslashes()
没有帮助;它是什么?如果打开js控制台,您将看到它被转到asdasD\Asdeqw.txt
因此,尝试添加另一个斜杠
'<a href="javascript:void(0);" onclick="openPhpFile (\'asdasD\\\Asdeqw.txt\');">efff</a>'
“”
如果打开js控制台,您将看到它被转到asdasD\Asdeqw.txt
因此,尝试添加另一个斜杠
'<a href="javascript:void(0);" onclick="openPhpFile (\'asdasD\\\Asdeqw.txt\');">efff</a>'
“”
您应该这样做:
<script type='text/javascript'>
(function () { // Closures are your friend
// Declare variables
var theDiv, theLink;
// Create the link and assign attributes
theLink = document.createElement('a');
theLink.innerHTML = 'efff';
theLink.href = '#';
theLink.onclick = function () {
openPhpFile('asdasD\\Asdeqw.txt');
};
// Get a reference to the container, empty the container and add the link
theDiv = document.getElementById('div');
theDiv.innerHTML = '';
theDiv.appendChild(theLink);
})();
</script>
(函数(){//闭包是您的朋友
//声明变量
var theDiv,theLink;
//创建链接并指定属性
theLink=document.createElement('a');
theLink.innerHTML='efff';
theLink.href='#';
theLink.onclick=函数(){
openPhpFile('asdasD\\Asdeqw.txt');
};
//获取对容器的引用,清空容器并添加链接
theDiv=document.getElementById('div');
theDiv.innerHTML='';
第四条附属物(theLink);
})();
请记住,如果您是
echo
ing双引号内的PHP,实际上需要4反斜杠。这是因为PHP也将使用双反斜杠序列,并且只输出一个。因此,如果希望PHP回显2个反斜杠,则需要在其中放入4个反斜杠。您应该这样做:
<script type='text/javascript'>
(function () { // Closures are your friend
// Declare variables
var theDiv, theLink;
// Create the link and assign attributes
theLink = document.createElement('a');
theLink.innerHTML = 'efff';
theLink.href = '#';
theLink.onclick = function () {
openPhpFile('asdasD\\Asdeqw.txt');
};
// Get a reference to the container, empty the container and add the link
theDiv = document.getElementById('div');
theDiv.innerHTML = '';
theDiv.appendChild(theLink);
})();
</script>
(函数(){//闭包是您的朋友
//声明变量
var theDiv,theLink;
//创建链接并指定属性
theLink=document.createElement('a');
theLink.innerHTML='efff';
theLink.href='#';
theLink.onclick=函数(){
openPhpFile('asdasD\\Asdeqw.txt');
};
//获取对容器的引用,清空容器并添加链接
theDiv=document.getElementById('div');
theDiv.innerHTML='';
第四条附属物(theLink);
})();
请记住,如果您是
echo
ing双引号内的PHP,实际上需要4反斜杠。这是因为PHP也将使用双反斜杠序列,并且只输出一个。因此,如果您想让PHP回显2个反斜杠,您需要在其中输入4个。您是否尝试过在每个反斜杠中输入4个而不是2或3个?您是否尝试过在每个反斜杠中输入4个而不是2或3个?只是想知道为什么需要在这里输入反斜杠?难道不是所有操作系统都支持(甚至更喜欢)正斜杠吗?也许我在Linux世界呆得太久了
我会使用正斜杠,至少是双反斜杠(显然不是引号)。我很想知道你在做什么,这意味着正斜杠行不通 只是想知道为什么这里需要反斜杠?难道不是所有操作系统都支持(甚至更喜欢)正斜杠吗?也许我在Linux世界呆得太久了 我会使用正斜杠,至少是双反斜杠(显然不是引号)。我很想知道你在做什么,这意味着正斜杠行不通 试试看:
var div = document.getElementById("div");
div.innerHTML = '<a>efff</a>';
div.firstChild.onclick = function () {
openPhpFile('asdasD\\\\Asdeqw.txt');
};
var div=document.getElementById(“div”);
div.innerHTML='efff';
div.firstChild.onclick=函数(){
openPhpFile('asdasD\\\\Asdeqw.txt');
};
试试:
var div=document.getElementById(“div”);
div.innerHTML='efff';
div.firstChild.onclick=函数(){
openPhpFile('asdasD\\\\Asdeqw.txt');
};
wee需要查看函数openPhpFile和.php文件来解决您的问题wee需要查看函数openPhpFile和.php文件来解决您的问题href应该是“#”之类的;没有理由认为它是“javascript:”虚假URL。@DaveRandom没有正确的方法是使用addEventListener
或attachEvent
,因为onClick
不兼容跨浏览器。请参见@AmirRaminfar虽然我不能对此进行反驳,但我不知道有哪一款(现代)浏览器不起作用——尽管我很高兴被纠正。除此之外,在jQuery中,这将是一行:)@AmirRaminfar在常规js中并没有那么糟糕,这是以最复杂的方式完成的。“href”应该是“#”或其他什么;没有理由认为它是“javascript:”虚假URL。@DaveRandom没有正确的方法是使用addEventListener
或attachEvent
,因为onClick
不兼容跨浏览器。请参见@AmirRaminfar虽然我不能对此进行反驳,但我不知道有哪一款(现代)浏览器不起作用——尽管我很高兴被纠正。除此之外,在jQuery中,这将是一行:)@AmirRaminfar在常规js中并没有那么糟糕,这是以最复杂的方式完成的。您完全正确,但遗憾的是,该文件使用了反斜杠:)典型的js丑陋。。。这就是我要说的。@JohnSmith…所以只要str\u replace(“\\\”、“/”、\uu FILE\uuuuuuuuu)
然后-它在Win上也能工作。你完全正确,但遗憾的是文件使用了反斜杠:)典型的JS丑陋。。。这就是我要说的。@JohnSmith…所以只要str\u replace(“\\\”、“/”、\uu FILE\uuuuuuuu)
然后-它在Win上仍然有效。嗯,没关系,如果文件名在一个变量中,我应该使用addslashes(addslashes()),所以两次?+1,我喜欢这个。没有href
的a
会不会导致页面重新加载?@DaveRandom我还没有测试过,至少在google chrome中没有,JohnSmith,你需要添加php代码,这样我们才能知道需要做什么..嗯,没关系,如果文件名在var中,我应该使用addslashes(addslashes()),所以两次?+1,我喜欢这样做。不带href
的a
会不会导致页面重新加载?@DaveRandom我还没有测试过,至少在google chrome中没有,JohnSmith,你需要添加php代码,这样我们才能知道需要做什么。。