'导出默认函数 评级(道具){ 常量 [悬停,setHover] =使用状态(假); // 检查悬停状态常量 [com, setCom] = use 状态(假); //检查点击状态
function isHover(){
setHover(true);} //connects to onMouseOver event then sets the hover state
function isNotHover(){ //connects to onMouseLeave event then sets the hover state
setHover(false);}
function op(){ //Send the Id of the rating button back to app.js so
props.op(props.id);} // it can be then forwarded to another page
function designs(){ //connects the click to sate, if the state is true it makes it false
com ? setCom(false):setCom(true)} // and vice verca
function bth(){ // I have two functions on click so this combines both
op() //the functions and gives it as one to the clicke event
designs()}
pressed //is style after clicked
rateStyle //is style before clicked
return(
<div style={hover|| com ? pressed: rateStyle} onMouseOver={isHover}
onMouseLeave={isNotHover} onClick={bth} >
{props.valN}
</div>)
}'我有五个评级按钮,我想在单击另一个按钮时取消单击已单击的按钮。通过点击我的意思是,当我点击其中一个按钮时,他们的样式主要改变为背景颜色,现在我希望当有人按下另一个评级时,我希望以前点击的按钮的样式恢复正常,新按下的按钮转到活动状态帮助。
这个问题我用了这个方法。
在你的纽扣里
<button id="button" onClick={
(e) => {
if(res === "unpressed"){
//if button is pressed for first
//time
e.target.style.backgroundColor ="rgb(195, 197, 64)";
setRes(pressed);
//Update res into false
}else{
//if button is pressed for second
//time
e.target.style.backgroundColor ="rgb(195, 17, 64)";
setRes(unpressed);
//Update res into false
}
}
}>
STAR
</button>
使用钩子
import { useState } from "react";
const [res,setRes] = useState("unpressed");
所以我有这些按钮(3叠6个,18个),我想实现的是当我按下其中一个按钮时: > 边框颜色 其他按钮将重置为其正常样式 但是我不想通过“isEnable”技巧禁用其他的(我只在这里找到了涉及isEnable的解决方案),我仍然希望它们被启用,我只是希望它们不要在按下时被我的自定义样式“突出显示”。 对于第一部分,也就是我在IBAction中所做的造型: 这一小部分只是一个按钮,但我想如果我有18个按
问题内容: 我希望我的应用程序中的按钮样式在按下时可以更改。做这个的最好方式是什么? 问题答案: 使用。 这里是一个例子:
} 完整错误消息:
问题内容: 我是Swing的新手。 我要在单击按钮(完成按钮)后更新表格。我认为数据正确,但屏幕无法正常工作。 以下是我程序的说明 选中复选框,然后单击完成按钮 最底层应更改。 没有主 这是我的代码: 问题答案: 而不是这样做… 只需更新现有模型 或简单地 假设您要继续向表中添加新行。如果您要这样做,还可以先清除表,然后再向其中添加新行。 Swing的工作原理是MVC(模型-视图- 控制器 ),该
问题内容: 可以更改按钮功能吗? 例如 点击,再点击一次 我已经尝试过类似,但没有结果。 我设法使叠加工作并在其中插入所需的数据。但是没有找到任何可以帮助我的帖子。我正在使用react-bootstrap。这是我的代码。 问题答案: 您可以尝试使用状态来存储颜色。也许这会让您想到解决问题的方法: 这是一个小提琴。
我在一个HTML页面上有2个按钮组。每组3到4个按钮(使用引导程序的按钮)。我想使用Javascript在没有onclick的情况下更改点击时的颜色按钮。 用户将单击组1中的任何按钮(单击“将颜色改为绿色”时),然后单击组2中的按钮,而不取消选择组1中的按钮。 null null