Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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 当我使用val()函数将所选文件的名称检索到以“quot”开头的输入标记中时,为什么要使用Chrome和IE;C:\fakepath\";?_Javascript_Jquery_Html_Html Input - Fatal编程技术网

Javascript 当我使用val()函数将所选文件的名称检索到以“quot”开头的输入标记中时,为什么要使用Chrome和IE;C:\fakepath\";?

Javascript 当我使用val()函数将所选文件的名称检索到以“quot”开头的输入标记中时,为什么要使用Chrome和IE;C:\fakepath\";?,javascript,jquery,html,html-input,Javascript,Jquery,Html,Html Input,使用Chrome和internetexplorer我发现以下问题与如何使用jQuery获取插入到输入标记中的文件名有关 因此,我有以下情况:在一个页面中,我有这个输入标记: <input id="rendicontoAllegato" class="form-control" style="height: 30px; padding: 0px;" type="file"> <div id="nomeDocumentoRendicontazione"></div&g

使用Chromeinternetexplorer我发现以下问题与如何使用jQuery获取插入到输入标记中的文件名有关

因此,我有以下情况:在一个页面中,我有这个输入标记:

<input id="rendicontoAllegato" class="form-control" style="height: 30px; padding: 0px;" type="file">
<div id="nomeDocumentoRendicontazione"></div>
正如您可以看到的,当用户在输入标记中选择新的fine时,将值更改为div havingid=“nomeDocumentoRendicontazione”

使用FireFox可以正常工作,如果我在div中选择一个文件名cat.jpg,我就得到了值cat.jpg

但是如果我使用Chrome或Internet Explorer,在div中选择文件后,我有以下值C:\fakepath\cat.jpg


为什么??如何在使用Chrome和Internet Explorer之前仅获取文件名而不获取**C:\fakepath**

    var selectedFileName = $("#rendicontoAllegato").val()
        .replace(/^C:.*\\/, '');          

那是因为安全原因。。。以下问题有一些很好的答案:


切掉
C:\fakepath\`可能带正则表达式?-*编辑*wow将
`作为代码字符串输入注释是一件棘手的事情:)相关阅读:
    var selectedFileName = $("#rendicontoAllegato").val()
        .replace(/^C:.*\\/, '');