【发布时间】:2017-03-26 10:38:42
【问题描述】:
我在我的项目中安装了一个名为 react-geosuggest 的 react-component。我需要在<Geosuggest> 组件中找到<label> dom 元素并将onClick 处理程序插入<label>。有没有办法在不改变<Geosuggest> 组件代码的情况下定位<label> 标记。
这里是 JSX
render() {
return (
<div>
<Geosuggest
id = "searchbar"
label = " "
placeholder = ""
initialValue = {this.state.location}
onChange = {this.onInputChange}
onSuggestSelect = {this.onSelection}
onClick = {this.toggleSearch}
className = {this.state.expand}
inputClassName = {this.state.expand}
// Name a calling reference
ref = 'geosuggest_component'
/>
</div>
);
}
这是 HTML 输出
<div class="geosuggest">
<div class="geosuggest__input-wrapper">
<label for="searchbar"></label>
<input class="geosuggest__input" type="text" id="searchbar">
</div>
</div>
【问题讨论】:
标签: javascript reactjs