gpt4 book ai didi

javascript - 无法在选择的更改时更新表字段

转载 作者:行者123 更新时间:2023-11-28 05:56:40 25 4
gpt4 key购买 nike

我的表结构如下:

<table>
<tr class="selected"><th>number</th><td><input type="number"/></td></tr>
<tr><th>name</th><td><input type="text"/></td></tr> ...
</table>

我已经创建了textarea并选择使用reactjs来更改thtd因此..代码:

var MySelect = React.createClass({
getInitialState: function() {
return {
value: '',
label: ''
}
},
change: function(event){
this.setState({value: event.target.value});
},
textChange:function(event){
this.setState({label: event.target.value});
},
render: function(){
if($('.selected').length >0 && $('.selected').find('td').length>0){ var stateValue = {this}; $('.selected').find('th')[0].innerHTML = stateValue.this.state.label; }
if($('.selected').length >0 && $('.selected').find('td').length>0){ var newTag = <input type={this.state.value}/>; $('.selected').find('td')[0].innerHTML = {newTag} }
return(
<div>
<p>Field label</p>
<textarea rows="3" cols="30" className="inputControl" id="field_name" onChange={this.textChange}></textarea><br />
<br />
<p>Field type</p>
<select className="inputControl" id="field_control" onChange={this.change} value={this.state.value}>
<option value="text">Textbox</option>
<option value="number">Number</option>
<option value="checkbox">Checkbox</option>
<option value="radio">Radio</option>
<option value="textarea">Textarea</option>
<option value="select">Dropdown</option>
<option value="multiple">Multiple Choice</option>
<option value="date">Date</option>
<option value="phone">Phone</option>
<option value="address">Address</option>
<option value="email">Email</option>
</select>
<br />
<br />
<div id="selectOption" style={{display: 'none'}}>
<p>
Choices
</p>
<div className="space">
<input type="text" className="inputControl" /></div>
<div className="space">
<input type="text" className="inputControl" /><span> <i className="fa fa-plus-circle icon add"
title="Add another choice"></i><i className="fa fa-minus-circle icon remove" title="Delete this choice">
</i></span>
</div>
<div className="space">
<input type="text" className="inputControl" />
<span><i className="fa fa-plus-circle icon add" title="Add another choice"></i><i className="fa fa-minus-circle icon remove"
title="Delete this choice"></i></span>
</div>
</div>
<p><input type={this.state.value} /></p>
</div>
);
}
});

帮助textarea更改th字段并选择更改 td字段..当我从选择选项中选择时,标签将更改 <p><input type={this.state.value} /></p>但它显示[OBJECT OBJECT]在错误行..我想更改 td根据选择选项中选择的值..我可以做什么 var newTag = <input type={this.state.value}/>; $('.selected').find('td')[0].innerHTML = {newTag}change: ?..我错过了什么吗?请推荐我..

更新我可以更改 th 值,但是当我单击第二个 td 并再次单击第一个 td 时,它会显示旧文本..

最佳答案

因此尝试使用 REDUX(一种 FLUX 实现)来实现它。您可以查看完整的文档 hereegghead上也有很多教程

关于javascript - 无法在选择的更改时更新表字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37609825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com