这是我的 React 组件
import React, { Component } from 'react';
import categories from './categories.json'
import './content.css'
export default class Content extends Component {
constructor(props) {
super(props)
this.state = {
searchText: '',
categories
}
}
render() {
return(
<div className="content">
<form className="searchform" onSubmit={this.search}>
<input type="text" name="keyword" id="searchbox" placeholder="Search String"></input>
<select name="categories" id="searchcategories">
<option defaultValue="" defaultChecked>Select a category</option>
{this.state.categories.map(x =>
<option key={x.value} value={x.value}>{x.name}</option>
)}</select>
<input type="submit" value ="Search" id="searchsubmit" />
</form>
</div>
)
}
search(e) {
console.log(e.target)
e.preventDefault();
}
}
单击提交按钮时,我的函数search
会被调用。但是,如何获取提交的值?
e.target
给我整个表单 DOM HTML
e.target.value
是undefined