3 javascript reactjs react-jsx redux
我有一个按钮和一个包含电子邮件地址的字符串属性。单击按钮后,我希望它打开带有字符串属性的电子邮件地址的 Mac 邮件/Windows 邮件收件人:
我该怎么做?任何指导或见解将不胜感激!
Kok*_*lav 10
您可以使用 window.location.href = `mailto:${this.props.email}`
class EmailButton extends Component {
constructor(props){
super(props);
this.onClick = this.onClick.bind(this);
}
onClick(){
window.location.href = `mailto:${this.props.email}`;
}
render(){
return <button onClick={this.onClick}>EmailButton</button>;
}
}
Run Code Online (Sandbox Code Playgroud)
你也可以使用 <a href={`mailto:${email}`}>EmailButton</a>