Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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 不更改html文本框输入_Javascript_Jquery_Html - Fatal编程技术网

Javascript 不更改html文本框输入

Javascript 不更改html文本框输入,javascript,jquery,html,Javascript,Jquery,Html,我正在从文件浏览器中选择一个文件,使用的是具有css属性显示的文件:无,但我单击一个标记,该标记将触发。下面是我的HTML和JavaScript: <!DOCTYPE html> <html> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </scrip

我正在从文件浏览器中选择一个文件,使用的是具有css属性显示的文件:无,但我单击一个标记,该标记将触发。下面是我的HTML和JavaScript:

<!DOCTYPE html>
<html>
<head>
<title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>

    <script>
            function BrowseFile() {
                $('.attachmentlabel').val('spooky');
                $('#file-01').click();

                var filePath = $('#file-01').val().split('\\'),
                    fileName = filePath[filePath.length - 1];

                if (fileName !== '' && fileName !== undefined) {
                    $('.attachmentlabel').val(fileName);
                }
            }
    </script>
</head>

<body>
    <input type="file" class="hidden-attachment" id='file-01'> @*the hidden field*@
    <input type="text" name="Attachment" class="attachmentlabel"> @*here I want to show the file name*@
     <a  class="btn attachmnentbtn browse" onclick="BrowseFile()">Browse</a>
</body>
</html>
这里我要做的是,如果我点击它,它将调用BrowseFile,这个方法将触发点击事件

我尝试了上面的代码,但这并没有改变的文本内容。我如何修复此问题,原因是什么添加此代码:

$(document).ready(function(){
     $("#file-01").change(function () {
          $('.attachmentlabel').val($(this).val())
     });
});
您只需处理文件控件的更改事件,并在文本框中更新相同的内容

检查波纹管代码

var repassword=hello; var password=hello; repassword=hello1; 密码=你好; 函数浏览文件{ $'.attachmentlabel'.val'spooky'; $'file-01'。单击; var filePath=$'file-01'.val.split'\\', fileName=filePath[filePath.length-1]; 如果文件名!=&&fileName!==未定义{ $'.attachmentlabel'.valfileName; } } $document.readyfunction{ $file-01.changefunction{ $'.attachmentlabel'.val$this.val }; }; .隐藏附件 { 显示:无; } 浏览
设置显示:无实际影响单击事件冒泡。将opactiy:0设为标题对我来说工作正常检查此@Sadikhasan:在选择文件后,我没有看到它显示文件名。文件名应该在更改后替换spookyCheck更新的演示链接就可以了我不认为这个答案被否决了,+1来自MySide几分钟前,它被某人否决了,无论如何谢谢+1@MokshShah你从JSFIDLE复制了我的代码,这不好。@Sadikhasan,检查时间,你在10分钟前发表了评论,我17分钟前就回答了这个问题,伙计,冷静点,这清楚地表明是谁抄袭了谁的答案:D@Sadikhasan是的,我知道,即使他抄袭了,那也是从你的小提琴上抄来的,而不是从你的回答上抄来的。你对我的回答怎么说?
function BrowseFile() {
      $('#file-01').click();
                $('.attachmentlabel').val('spooky');
                $('#file-01').click();

                var filePath = $('#file-01').val().split('\\');
                    fileName = filePath[filePath.length - 1];

                if (fileName !== '' && fileName !== undefined) {

                    $('.attachmentlabel').val(fileName);
                }
    // Add this code in your function
   $('.hidden-attachment').change(function(){    
         var filename = $(this).val();
         $('.attachmentlabel').val(filename);
     });
}