【发布时间】:2021-02-24 22:35:23
【问题描述】:
我尝试设置一个 onClick 事件以使用 tsx.react 打开一个弹性框。按钮和弹性框显示正确,但 vscode 显示 onClick 事件有问题。我不知道出了什么问题,但也许你可以。我是该领域的新手,并尝试了堆栈社区的一些想法,但对我没有用。
控制台告诉我必须分配“字符串”,但它也不起作用。
//Function to change visibility of the flexBox
document.getElementById("OpenProfiles")
.addEventListener("click", ProfilesOpn);
function ProfilesOpn () {
var a = document.querySelectorAll(".ProfilesOpen")[0];
var b = document.querySelectorAll(".ProfilesClose")[0];
a.style.visibility = "hidden"
b.style.visibility = "visible";
}
//the button code inside the flexbox
<div className={"Profiles"}>
<div className={"Profile1"}>
<div className={"Profile1P"}></div>
<h3 className={"ProfileH3"}>Profile1</h3>
</div>
<div className={"Profile2"}>
<div className={"Profile2P"}></div>
<h3 className={"ProfileH3"}>Profile2</h3>
</div>
<div className={"Profile3"}>
<div className={"Profile3P"}></div>
<h3 className={"ProfileH3"}>Profile3</h3>
</div>
<div className={"Profile4"}>
<div className={"Profile4P"}></div>
<h3 className={"ProfileH3"}>Profile4</h3>
</div>
<h3 className={"EndCoPro"}>Are you missing any profiles?</h3>
<button id="OpenProfiles" onClick="return(ProfilesOpn());">
<div className={"ProfilesOpen"}><img src={ProfilesOpen} alt="Open Profiles"/></div>
</button>
</div>
//the code in sass for the styling
.Profiles {
position: absolute;
display: flex;
left: 0px;
bottom: 0px;
width: 300px;
height: 900px;
flex-direction: column;
justify-content: flex-start;
align-items: space-between;
background-color: #292929;
box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.2);
border-top-right-radius: 25px;
border-bottom-right-radius: 25px;
visibility: hidden;
}
【问题讨论】:
-
如果您愿意,我可以将出现的问题的屏幕截图发送给您。如果您还需要其他东西,请告诉我。
-
感谢截图!使用 code/codesandbox 链接更新了答案。如果这对您有帮助,请投票/接受答案。
标签: html typescript react-native sass tsx