假设我有这个HTML:
<div id="container"></div>
<p>Output: <span id="output"></span></p>而这个JS:
function otherAction(e) {
document.getElementById('output').innerHTML = 'otherAction';
e.preventDefault();
}
function submit(e) {
document.getElementById('output').innerHTML = 'submit';
e.preventDefault();
}
ReactDOM.render(
<form onSubmit={submit}>
<input type="text" defaultValue="foo" />
<button onClick={otherAction}>Other Action</button>
<button type="submit">Submit</button>
</form>,
document.getElementById('container')
);事实上,我们不能简单地说,让我们将其放在JSFiddle示例中。我想要的是:
otherAction函数(确实如此!)submit函数(确实如此!)submit函数(这目前不起作用!)在#3中,所发生的情况是触发了otherAction。我怎么才能改变呢?
https://stackoverflow.com/questions/39548467
复制相似问题