jQuery 中有什么错误

乔恩

在代码下方,vanilla javascript 版本运行良好,但我尝试编写的 jQuery 版本不会对输入文本产生更新。jQuery 中有什么错误,因为我似乎无法发现它。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title> Total Tutor </title>
  <link type="text/css" rel="stylesheet" href="query.css">
  <script src="../jquery.js"></script>
</head>

<body>
  <div id="main">
    <button class="fileUpload">
<input id="uploadBtn" type="file" class="upload">
</button>
    <input id="uploadFile" placeholder="0 files selected" disabled="disabled">

  </div>
</body>
</html>

<script>
  $("#uploadBtn").change(function() {

    var value = $(this).val();
    $("#uploadFile").val(value);

  });


  //this works fine 

  // document.getElementById("uploadBtn").onchange = function () {
  //     document.getElementById("uploadFile").value = this.value;
  // };
</script>

格米特·辛格 |

请试试这个:

$(function() {
     $("input:file").change(function (){
       var fileName = $(this).val();
       alert(fileName);
       // do whatever you want to do with file name
     });
 });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章