Javascript e、 target.href在firefox中不工作
e、 target.href在firefox中不起作用。这只适用于chrome。我尝试了以下问题的解决方案(),但仍然无法在firefox上工作。我还需要补充什么吗 app.jsJavascript e、 target.href在firefox中不工作,javascript,firefox,reactjs,events,Javascript,Firefox,Reactjs,Events,e、 target.href在firefox中不起作用。这只适用于chrome。我尝试了以下问题的解决方案(),但仍然无法在firefox上工作。我还需要补充什么吗 app.js showModal(e) { if (!e) { e = window.event; } e.preventDefault(); const event = e.target || e.srcElement; const url = event.href; c
showModal(e) {
if (!e) {
e = window.event;
}
e.preventDefault();
const event = e.target || e.srcElement;
const url = event.href;
console.log('url', url, event.href);
const redirectTo = url.substring(url.lastIndexOf('/') + 1);
this.setState({ show: true });
this.context.router.transitionTo(redirectTo);
}
<Nav
showModal={(e) => this.showModal(e)}
hideModal={() => this.hideModal()}
show={this.state.show}
onHide={() => this.hideModal()}
/>
<button
className="btn btn-default"
onClick={(e) => props.showModal(e)}
>
<Link to={{ pathname: '/signup' }}>
{props.intl.formatMessage({ id: 'nav.registration.text' }) }
</Link>
</button>
showmodel(e){
如果(!e){
e=窗口事件;
}
e、 预防默认值();
常量事件=e.target | | e.src元素;
const url=event.href;
log('url',url,event.href);
const redirectTo=url.substring(url.lastIndexOf('/')+1);
this.setState({show:true});
this.context.router.transitiono(重定向到);
}
这个.showmodel(e)}
hideModal={()=>this.hideModal()}
show={this.state.show}
onHide={()=>this.hideModal()}
/>
Nav.js
showModal(e) {
if (!e) {
e = window.event;
}
e.preventDefault();
const event = e.target || e.srcElement;
const url = event.href;
console.log('url', url, event.href);
const redirectTo = url.substring(url.lastIndexOf('/') + 1);
this.setState({ show: true });
this.context.router.transitionTo(redirectTo);
}
<Nav
showModal={(e) => this.showModal(e)}
hideModal={() => this.hideModal()}
show={this.state.show}
onHide={() => this.hideModal()}
/>
<button
className="btn btn-default"
onClick={(e) => props.showModal(e)}
>
<Link to={{ pathname: '/signup' }}>
{props.intl.formatMessage({ id: 'nav.registration.text' }) }
</Link>
</button>
props.showmodel(e)}
>
{props.intl.formatMessage({id:'nav.registration.text'})}
尝试使用getAttribute()
showmodel(e){
如果(!e){
e=窗口事件;
}
e、 预防默认值();
const tgt=e.target | | e.src元素;
const url=tgt.getAttribute('href');
log('url',url,tgt);
const redirectTo=url.substring(url.lastIndexOf('/')+1);
this.setState({show:true});
this.context.router.transitiono(重定向到);
}
我也试过了。我在firefox中得到null,但它在chrome中工作,而且我不需要操纵字符串。剥猫皮的方法不止一种——试试:var xHref=tgt.getAttributeNode(“href”)。value
什么是“在firefox中不工作”?你得到了什么?