在代码中,我在Option组件上应用了onClick事件处理程序,它在单击时触发noBorder函数,但在单击该函数时不起作用,因为我在控制台中没有得到‘Hello’.但是,在Container组件中应用相同的事件处理程序会起作用.有谁能告诉我哪里出错了吗?
const Navbar = () => {
const noBorder = (e) => {
// e.preventDefault();
// e.currentTarget.style.border = "none";
console.log("hello");
};
return (
<Container>
<LogoWrapper>
<Logo src={logo} alt="image not found"></Logo>
</LogoWrapper>
<LanguageSelector>
<GlobeIcon src={globe} alt="image not found" />
<label htmlFor="language">
<LanguageButton name="language">
<Option value="english" onClick={noBorder}>
placeholder
</Option>
<Option value="hindi" onClick={noBorder}>
placeholder
</Option>
</LanguageButton>
</label>
</LanguageSelector>
</Container>
);
};
const Container = styled.div`
`;
const Logo = styled.img`
`;
const LogoWrapper = styled.div`
`;
const LanguageButton = styled.select`
`;
const Option = styled.option`
`;
const GlobeIcon = styled.img`
`;
const LanguageSelector = styled.div`
`;