直接获取上传文件的input值

Posted on 2015-06-08 11:57  小蕊同学  阅读(2055)  评论(0编辑  收藏  举报
js函数
  1. <script>
  2. function m(i){
  3. var url=i.value;
  4. url=url.split("\\");
  5. var n = url[url.length-1];
  6. n = n.substring(0,n.lastIndexOf('.'));
  7. document.getElementById('title').value = n;
  8. }
  9. </script>
  1. 资质描述<input type="text" name="ztitle" id="title"><br>
  2. 资质上传<input type="file" name="zzfile" onChange="m(this)"><br>
把资质上传的文件名直接填写在资质描述中
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>无标题文档</title>
  6. </head>
  7. <body>
  8. <h1>企业荣誉资质</h1>
  9. <form action="zzsave.php" method="post" enctype="multipart/form-data">
  10. 类别:<select name="cname">
  11. <?php
  12. include '../inc/db_mysqli.php';
  13. $rows=query('hnsc_zzclass');
  14. foreach($rows as $v){
  15. printf("<option value='%s'>%s</option>",$v[0],$v[0]);
  16. }
  17. ?>
  18. </select>
  19. <button onClick="location.href='zzclassadmin.php';">新增类别</button><br>
  20. 资质描述<input type="text" name="ztitle" id="title"><br>
  21. 资质上传<input type="file" name="zzfile" onChange="m(this)"><br>
  22. 是否在网站上显示
  23. <label><input type="radio" name="flag" value="y" checked>显示</label>
  24. <label><input type="radio" name="flag" value="n">不显示</label><br>
  25. <input type="submit" value="提交">
  26. <script>
  27. function m(i){
  28. var url=i.value;
  29. url=url.split("\\");
  30. var n = url[url.length-1];
  31. n = n.substring(0,n.lastIndexOf('.'));
  32. document.getElementById('title').value = n;
  33. }
  34. </script>
  35. </form>
  36. </body>
  37. </html>







Copyright © 2024 小蕊同学
Powered by .NET 8.0 on Kubernetes