
在现代web应用中,为用户提供高效的搜索功能是至关重要的。当搜索结果需要从多个外部资源获取,并且每个资源可能需要不同的查询参数时,前端javascript的动态url构建和多标签页管理能力就显得尤为重要。本教程将引导您实现一个这样的搜索界面,允许用户输入搜索词,选择多个区域,并自动在新标签页中打开相应的搜索结果页面。
首先,我们需要一个清晰的HTML结构来承载搜索输入、类型选择和区域选择。以下是核心的HTML元素:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MESA Canada Search</title>
<!-- 引入CSS文件,例如 /canada.css -->
<link rel="stylesheet" href="/canada.css">
<!-- 引入JavaScript文件,使用 defer 属性确保HTML解析完成后执行 -->
<script defer src="/canada.js"></script>
</head>
<body>
<div class="container">
<p class="title">MESA Canada</p>
</div>
<!-- 公司搜索字段 -->
<div id="company-search-field">
<input id="company-name" name="company-name" style="background-color: white; margin-left: 1rem; width: 300px; line-height: 5;" placeholder="Insert company name here" />
</div>
<!-- 个人搜索字段 (初始隐藏) -->
<div id="person-search-field" style="display: none;">
<input id="first-name" name="first-name" style="background-color: white; margin-left: 1rem; width: 300px; line-height: 5;" placeholder="Insert person first name here" />
<input id="last-name" name="last-name" style="background-color: white; margin-left: 1rem; width: 300px; line-height: 5;" placeholder="Insert person last name here" />
</div>
<br>
<!-- 搜索类型选择 (单选按钮) -->
<div class="search-subject" style="margin-left: 1rem;">
<input type="radio" onclick="displayPersonOrCompanySearchFields()" id="company-subject" name="subject-type" value="company-subject" checked>
<label for="company-subject">Company</label>
<input type="radio" onclick="displayPersonOrCompanySearchFields()" id="person-subject" name="subject-type" value="person-subject">
<label for="person-subject">Person</label>
</div>
<br></br>
<!-- 公司搜索状态选择区域 -->
<div id="company-search-states">
<div class="states-dropdown-list">
<form action="" onsubmit="return false;" style="width: 620px; border-right: solid; line-height: 2rem; border-color: darkgreen;">
<b style="margin-left: 1rem;"><span style="color: darkgreen;">Corporate Records</span> and <span style="color: darkgreen;">Litigation</span> Research</b>
<!-- 地理图标等装饰性SVG -->
<div style="border-radius: 25px; width: 30px; height: 30px; flex: auto; margin-top: -2rem; margin-left: 26rem; background-color: black;">
<svg style="color: white; background-color: transparent; margin-left: 0.4rem; margin-top: 0.4rem;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-geo" viewBox="0 0 16 16以上就是JavaScript搜索查询实现与多标签页管理教程的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号