点击 开关按钮的时候,一直不响应,没有任何的反应。请问这个是什么原因呢?

我有代码如下:

import React from 'react'

function App5() {

  const handleClick = () => {
    console.log(123)
  }

  return (      
    <div
      style={{ position: 'relative', height: '100vh' }}
    >
     
      <div id="header" style={{ width: '100%', height: '24px', backgroundColor: '#ddd',
        display: 'flex', justifyContent: 'flex-end'
    }}>  
      {/* Q1: 如何让区域1 在中间呢? */}
          <span>  区域1 </span>  

      {/* Q2: 没有响应点击事件 */}
          <button 
            onClick={ handleClick}
          >开关</button>
      </div>


      <div id="content" style={{  position: 'absolute', top: '24', bottom: '24px', width: '100%', height: '100%' }}>


      </div>

      <div id="footer" style={{  position: 'absolute', bottom: 0, width: '100%', height: '24px', backgroundColor: '#3472BB' }}></div>
    </div>
  )
}

export default App5

展示效果为:
image.png

但是在我点击 开关按钮的时候,一直不响应,没有任何的反应。

1、请问按钮不响应的原因是什么呢?

2、如何让<span> 元素(内容为:区域1 )居中呢?

阅读 2.8k
1 个回答

1、没看出哪里有问题,主要检测事件名变量名有没有写对,元素有没有被遮盖,console有没有被重写等
2、可以给span加上margin: 0 auto;进行居中

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题