2023-08-02T13:34:06.png

HTML 代码:

<input type="text" id="search-input">
<button id="search-btn">搜索</button>

JavaScript 代码:

const searchInput = document.getElementById('search-input');
const searchBtn = document.getElementById('search-btn');

searchBtn.addEventListener('click', function() {
  const keyword = encodeURIComponent(searchInput.value.trim());
  const url = `https://www.baidu.com/s?wd=${keyword}`;
  window.open(url, '_blank');
});