• 全部
...

为什么onclick()不生效

ahrisama 2016-03-08 08:51:50

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Upload information</title>
  6. </head>
  7. <body>
  8. <div id="dcontent">
  9. <form method="post" enctype="multipart/form-data">
  10. <div id="dinfo">
  11. <table id="tMemberInput">
  12. <tr>
  13. <td>
  14. <button onclick="myFunction3()">byhand</button>
  15. <button onclick="myFunction4()">excel</button>
  16. <div id="byhand" style="display:block">//对于 type为text的表单所在div
  17. <form method="post" enctype="multipart/form-data" >
  18. <table id="paper">
  19. <tr>
  20. <td>Title</td>
  21. <td><input type="text" name="session"></td>
  22. </tr>
  23. <tr>
  24. <td>Author</td>
  25. <td><input type="text" name="author"></td>
  26. </tr>
  27. <tr>
  28. <td>E-Mail</td>
  29. <td><input type="text" name="email"></td>
  30. </tr>
  31. </table>
  32. </form>
  33. </div>
  34. <div id="excel" style="display:none">//对于 type为excel的表单所在div
  35. <form method="post" enctype="multipart/form-data">
  36. <input type="file" name="excel">
  37. </form>
  38. </div>
  39. </td>
  40. </tr>
  41. <tr>
  42. <td>
  43. <table id="tMemberExcel">
  44. </table>
  45. </td>
  46. </tr>
  47. </table>
  48. </div>
  49. <div id="dSubmit">
  50. <input type="submit" name="submit" value="SUMBIT">
  51. </div>
  52. </form>
  53. </div>
  54. <script>
  55. function myFunction3()
  56. {
  57. var byhand =document.getElementById("byhand");
  58. byhand.style.display="block";
  59. var excel =document.getElementById("excel");
  60. excel.style.display="none";
  61. }
  62. </script>
  63. <script>
  64. function myFunction4()
  65. {
  66. var byhand =document.getElementById("byhand");
  67. byhand.style.display="none";
  68. var excel =document.getElementById("excel");
  69. excel.style.display="block";
  70. }
  71. </script>
  72. </body>
  73. </html>

页面理想的设计效果是单击一个button,就会出现 type为text的表单
单击另一个button就会出现type为file的表单
设计思路是通过控制两个div的display属性,出现的可能性只能是block/none或none/block
可是实际是单击其中某一个button,可以加载onclick(),但是在很快就恢复成初始页面。
试过用alert()测试,出现提示框有预期的理想效果,单击确定后又恢复了
求解是哪里出现问题了
或者有没有其他设计方案
...全文
给本帖投票
563 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2016-03-08
  • 打赏
  • 举报
回复
引用 1 楼 jslang 的回复:
button标签默认是提交表单的行为。 改为 <input type="button" value="byhand" onclick="myFunction3();" /> 或 <button type="button" onclick="myFunction3()">byhand</button>
ahrisama 2016-03-08
  • 打赏
  • 举报
回复
引用 1 楼 jslang 的回复:
button标签默认是提交表单的行为。 改为 <input type="button" value="byhand" onclick="myFunction3();" /> 或 <button type="button" onclick="myFunction3()">byhand</button>
之前没声明类型所以默认是submit吗?
天际的海浪 2016-03-08
  • 打赏
  • 举报
回复
button标签默认是提交表单的行为。 改为 <input type="button" value="byhand" onclick="myFunction3();" /> 或 <button type="button" onclick="myFunction3()">byhand</button>

87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧

手机看
关注公众号

关注公众号

客服 返回
顶部