ITPub博客

首页 > IT职业 > IT图书 > 下拉选择框与输入框联动,直接添加选中值到输入框

下拉选择框与输入框联动,直接添加选中值到输入框

原创 IT图书 作者:chunzhisu 时间:2014-07-24 11:37:08 0 删除 编辑
  • 下拉选择框与输入框联动,直接添加选中值到输入框中,这种效果相信不少朋友见到过吧,省去用户输入的麻烦,这里使用JS直接将值赋予输入框,了解原理之后,可灵活运用,扩展出更多的特效来。


点击(此处)折叠或打开

  1. <html>
  2. <head>
  3. <title>下拉选择框与输入框联动,直接添加选中值到输入框</title>
  4. </head>
  5. <body>
  6. <select id=\"uiSel\">
  7.     <option value=\"-1\">请选择</option>
  8.     <option value=\"until1\">unti1</option>
  9.     <option value=\"until2\">unti2</option>
  10.     <option value=\"until3\">unti3</option>
  11.     <option value=\"until4\">unti4</option>
  12.     <option value=\"until5\">unti5</option>
  13. </select>
  14. <input type=\"text\" name=\"\" id=\"show\" />
  15. </body>
  16. <script type=\"text/javascript\">
  17. document.getElementById(\'uiSel\').onchange=function (){
  18.     if(this.options[0].value==-1)this.options[0]=null;
  19.     document.getElementById(\'show\').value=this.value
  20. };
  21. </script>
  22. </html>


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29737856/viewspace-1226056/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-04

  • 博文量
    95
  • 访问量
    122213