Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在JSX中添加超链接_Javascript_Reactjs - Fatal编程技术网

Javascript 如何在JSX中添加超链接

Javascript 如何在JSX中添加超链接,javascript,reactjs,Javascript,Reactjs,我想在JSX中创建一个超链接按钮。我试着研究如何做到这一点。这里也有类似的问题,但我不知道为什么我的代码不起作用。我正在使用scrimba编辑器。这是我的密码: import React from 'react'; import ReactDOM from 'react-dom'; import styled from 'styled-components' const Button = styled.button` background-color: #e2e86f; height:

我想在JSX中创建一个超链接按钮。我试着研究如何做到这一点。这里也有类似的问题,但我不知道为什么我的代码不起作用。我正在使用scrimba编辑器。这是我的密码:

import React from 'react';
import ReactDOM from 'react-dom';
import styled from 'styled-components'

const Button = styled.button`
 background-color:  #e2e86f;
 height: 50px;
 width: 100px;
 border-radius: 5px;
 `
 
 function SignUp(){
   <link href="https://google.com"/>
 }

 function SignIn(){
   alert('Signed In!')
 }

class Main extends React.Component {
  render() {
    return (
      <div>
      <h1 style={{color: "white"}}><center>Adope</center></h1>
      <h3 style={{color: "white"}}>Why Adope</h3>
      <ul>
      <li style= {{color: "white"}}>It is safe</li>
      <li style={{color: "white"}}>Gives you 2 weeks returning option</li>
      <li style={{color: "white"}}>Gives you a proper description of the product</li>
      <li style={{color: "white"}}>Has no software error</li>
      
      </ul>
      <center><h2 style={{color:"white"}}><center>Sign Up to Get Started
</center> </h2>      
      <p><center><Button style={{color:"white"}}onClick={SignUp}>

      Sign Up
      </Button></center></p>
      
      <p><center><Button style={{color:"white"}}onClick={SignIn}>

      Sign In
      </Button></center></p>
      </center>
      </div>
    );
  }
}

ReactDOM.render(<Main />, document.getElementById('home'));
从“React”导入React;
从“react dom”导入react dom;
从“样式化组件”导入样式化
const Button=styled.Button`
背景色:#e2e86f;
高度:50px;
宽度:100px;
边界半径:5px;
`
函数注册(){
}
函数签名(){
警报('已登录!')
}
类Main扩展了React.Component{
render(){
返回(
阿多普
为什么要偷懒
    这是安全的
  • 为您提供2周的返回选项
  • 为您提供产品的正确描述
  • 没有软件错误
注册开始吧 注册

登录

); } } ReactDOM.render(,document.getElementById('home');

一切都在运行,但当我单击“注册”按钮时,它不会将我重定向到谷歌。

在您的
注册
功能中,您需要通过分配
窗口.位置.href
将用户重定向到新的url:

 function SignUp(){
   window.location.href = "https://google.com";
 }
函数注册(){
window.location.href=”https://google.com";
}
或者,如果您希望在新窗口中打开链接:

函数注册(){
窗口打开(“https://google.com");
}

在您的
注册
功能中,您需要通过分配
window.location.href
将用户重定向到新的url:

函数注册(){
window.location.href=”https://google.com";
}
或者,如果您希望在新窗口中打开链接:

函数注册(){
窗口打开(“https://google.com");
}

我建议您先学习HTML/CSS/JS,然后再尝试React

您正试图将
标记用作
我建议您先学习HTML/CSS/JS,然后再尝试React

您正试图将
标记用作


使用带有
href
的锚定,而不是带有
onClick的按钮
使用带有
href
的锚定,而不是带有
onClick的按钮
是的,它的工作方式是:谢谢,谢谢
<a style={{color:"white"}} href="https://google.com">
  Sign Up
</a>