Javascript 当用户点击进入按钮时,如何停止触发按钮?
我对react js是新手,我有点困惑,当用户点击Enter按钮时,如何停止触发简单按钮。。。 对不起,我的代码会很尴尬。。。。。。如果阅读起来不舒服,请随意评论Javascript 当用户点击进入按钮时,如何停止触发按钮?,javascript,html,reactjs,Javascript,Html,Reactjs,我对react js是新手,我有点困惑,当用户点击Enter按钮时,如何停止触发简单按钮。。。 对不起,我的代码会很尴尬。。。。。。如果阅读起来不舒服,请随意评论 import React from 'react'; import {connect} from 'react-redux'; import {Link} from 'react-router'; import * as headerAction from '../../Actions/headerActions'; import *
import React from 'react';
import {connect} from 'react-redux';
import {Link} from 'react-router';
import * as headerAction from '../../Actions/headerActions';
import * as notificationActions from '../../Actions/notificationActions';
import * as tagProfileActions from '../../Actions/tagProfileActions';
class TagProfile extends React.Component{
static contextTypes = {
router:React.PropTypes.object
};
constructor(props){
super(props)
this.state = {
data:[],
tagName:"",
In:null,
tagId:"",
tagFollowers:0,
isFollowStatus:""
}
this.handleFollow =this.handleFollow.bind(this)
}
handleFollow(e){
//How to Prevent this
console.log(e.keyCode)//Udefined
e.preventDefault();
console.log('Clicked')
}
render(){
console.log(this.state)
return (
<div className="ContainerForTagProfile">
<div className="TagProfileTopSecTion">
<h1>Topic: {this.state.tagName} </h1>
</div>
<div className="StatusBarRealTimeViewsAndFollowButtn">
<div className="ViewCcountBar">
<p>30,18,5222 Finally I got Solution
Just added KeyDown and Onclick Evt And Throwed some if else statement for KeyBoard Events..
handleFollow(e){
e.preventDefault()
if(e.type !== 'keydown'){
//Start Code From here
}
}
从“React”导入React;
从'react redux'导入{connect};
从“反应路由器”导入{Link};
从“../../Actions/headerActions”导入*作为headerAction;
从“../../Actions/notificationActions”导入*作为notificationActions;
从“../../Actions/tagProfileActions”导入*作为tagProfileActions;
类TagProfile扩展了React.Component{
静态上下文类型={
路由器:React.PropTypes.object
};
建造师(道具){
超级(道具)
此.state={
数据:[],
标记名:“”,
In:null,
标记ID:“”,
跟踪者:0,
isFollowStatus:“
}
this.handleFollow=this.handleFollow.bind(this)
}
把手下面(e){
//如何防止这种情况
console.log(e.keyCode)//
e、 预防默认值();
console.log('Clicked')
}
render(){
console.log(this.state)
返回(
主题:{this.state.tagName}
30,185222我终于找到了答案
刚刚添加了KeyDown和Onclick Evt,并抛出了一些if-else语句用于键盘事件