search.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // 获取input框
  2. var input_box = document.getElementById("Search-input");
  3. // 获取百度按钮
  4. var baidu_btn = document.getElementById("Search-button");
  5. // 键盘事件
  6. input_box.onkeydown = function () {
  7. // 当按下回车键根据input值跳转页面
  8. if (event.keyCode == 13) {
  9. window.location.href = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd="+input_box.value;
  10. };
  11. };
  12. // 单击百度一下按钮触发事件
  13. baidu_btn.onclick = function () {
  14. var input_value = input_box.value;
  15. if (input_value == "" || input_value == null) {
  16. window.location.reload();
  17. } else {
  18. window.location.href = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd="+input_value;
  19. };
  20. };
  21. // 获取模块框
  22. var Modul = document.getElementById("Modul");
  23. // 获取more_bar框
  24. var moreBar = document.getElementById("more_bar");
  25. // 监听滚轮事件
  26. window.onscroll = function () {
  27. Modul.style.height = "auto";
  28. moreBar.style.display = "none";
  29. }
  30. // 下拉箭头点击事件
  31. moreBar.onclick = function () {
  32. Modul.style.height = "auto";
  33. moreBar.style.display = "none";
  34. }