在代码中,我在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`
`;

推荐答案

option是一种特殊的HTML标记,作为select的一部分呈现,因此交互和样式非常有限.这与styled-components无关,因为props 只是传递下go 的.有关更深入的答案,请参阅here.

Reactjs相关问答推荐

安装后未渲染tailwind

将对象添加到集合中的数组时的no_id字段

Reaction Axios多部分/表单-数据数组不工作

下拉Tailwind CSS菜单与怪异beviour

TypeError:SearchProduct.get()获得了意外的关键字参数查询'

使用下一步中的路由/导航不会立即加载路由

如何在物料界面react 的多选菜单中设置最大 Select 数限制

REACTION-Easy-SORT返回.map错误

使用获取的数据更新状态,但在try console.log 时它给出未定义

如何解决使用react-hook-form和yup动态创建的输入不集中的问题

如何在 ChartJS 中创建此图表?在 NEXTjs 和 TSX 中

使用reactrouterdom时显示"对象无效作为React子组件"错误

React Js和Firestore中如何将当前ID与集合中的ID查询以仅显示具有相似字段和值的文档-第二部分

cypress `cy.now()` Type 'Promise' 没有调用签名

使用 React Router v6 监听来自不同组件的组件状态变化

Material UI:使用 mui 手风琴时出现props 类型失败:isValidElement 不是函数

导航到屏幕时,react 本机上下文状态变为未定义

CORS 政策:无访问控制允许来源-AWS 和 Vercel

React - useParams() 不会失败 null / undefined 判断

React 似乎在触发另一个组件时重新渲染了错误的组件