检查按钮是否处于活动状态,然后获取其值以传递按钮
function Input() {
const [input, setInput] = useState("");
function handleSearch() {
let url = "https://google.com/search?q=${input}"
window.open(url)
}
return (
<div className="input-wrap">
<input
type="text"
className="input__search"
placeholder="Enter your search..."
value={input}
onChange={(e) => setInput(e.target.value)}></input>
<button
className="input__search--btn"
onClick={handleSearch}>
<i className="fa-solid fa-magnifying-glass"></i>
</button>
</div>
);
}
单击搜索按钮时,将根据输入字段中的值将您重定向到 google 搜索,下面是高级搜索的站点,激活后,链接将在后面添加一个附加链接“https://google.com/search?q=${input}+site%3A${activepage}.com
,如何检查一个或多个网站是否处于活动状态,然后传递其name to url
P/s:切换网站的代码
function WebButton({ icon, name }) {
const [active, setActive] = useState(false);
function handleToggle() {
setActive(!active);
}
return (
<button
className={active ? "websites-btn active" : "websites-btn"}
onClick={handleToggle}>
<i className={icon}></i>
<div className="websites-name">{name}</div>
</button>
);
}
function Input() {
const [input, setInput] = useState("");
function handleSearch() {
let url = "https://google.com/search?q=${input}"
window.open(url)
}
return (
<div className="input-wrap">
<input
type="text"
className="input__search"
placeholder="Enter your search..."
value={input}
onChange={(e) => setInput(e.target.value)}></input>
<button
className="input__search--btn"
onClick={handleSearch}>
<i className="fa-solid fa-magnifying-glass"></i>
</button>
</div>
);
}
The search button when clicked will redirect you to a google search based on the value from the input field, below is the site for advanced search, when active the link will add an additional link after "https://google.com/search?q=${input}+site%3A${activepage}.com
, how do I check if one or many sites are active then pass down its name to url
P/s: code for toggling websites
function WebButton({ icon, name }) {
const [active, setActive] = useState(false);
function handleToggle() {
setActive(!active);
}
return (
<button
className={active ? "websites-btn active" : "websites-btn"}
onClick={handleToggle}>
<i className={icon}></i>
<div className="websites-name">{name}</div>
</button>
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以保留根级别状态来收集状态的活动链接。并将其传递给
Input
组件。Input
组件以接受名为 `` 的数组,并更新handleSearch
以在 Google 搜索中使用OR
操作。WebButton
中名为toggleActiveLink
的另一个函数和一个名为value
的字符串,该字符串引用 URL 部分。使用handleToggle
函数内的值调用该函数。You can keep a root level state to gather active links to a state. And pass it to the
Input
component.Input
component to accept array called `` and update thehandleSearch
to useOR
operation in google search.WebButton
calledtoggleActiveLink
and a string calledvalue
which refers to the URL part. Call the function with the value insidehandleToggle
function.