2023-08-02T13:44:10.png

html

<div id="search-box">
  <input type="text" id="search-input" class="search-input">
  <button class="search-btn" data-engine="baidu">百度搜索</button>
  <button class="search-btn" data-engine="bing">bing搜索</button>
  <!-- 其他搜索框和按钮 -->
</div>

JavaScript

    const searchBox = document.getElementById('search-box');

searchBox.addEventListener('click', function(event) {
  if (event.target.classList.contains('search-btn')) {
    const input = document.getElementById('search-input');
    const keyword = encodeURIComponent(input.value.trim());
    const engine = event.target.dataset.engine;
    let url;

    switch (engine) {
      case 'baidu':
        url = `https://www.baidu.com/s?wd=${keyword}`;
        break;
      case 'bing':
        url = `https://www.bing.com/search?q=${keyword}`;
        break;
      // 其他搜索引擎的处理逻辑
      default:
        url = '';
        break;
    }

    if (url) {
      window.open(url, '_blank');
    }
  }
});