我有正負號的文本框,可以添加新的文本框並相應地移除點擊的文本框..我想添加onclick加上使用reactjs ..我可以隱藏選定的文本框(對於此功能是:removeChoice),但不能添加文本框(該功能是:addChoice)使用reactjs添加動態標籤
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});
},
addChoice: function(event) {
var a = event.currentTarget.parentNode.parentNode;
$(a).append(); //HERE
},
removeChoice: function(event) {
var a = event.currentTarget.parentNode;
$(a).css('display','none');
},
render: function(){
if($('.selected').length >0 && $('.selected').find('th').length>0 && this.state.label!=''){ $('.selected').find('th')[0].innerHTML = this.state.label; }
if($('.selected').length >0 && $('.selected').find('td').length>0 && this.state.value!='') {
if(this.state.value == "textarea") $('.selected').find('td')[0].innerHTML = '<textarea rows="4" cols="20"></textarea>';
else if(this.state.value == "select") $('.selected').find('td')[0].innerHTML = "<select style='width: 40%'><option></option</select>";
else $('.selected').find('td')[0].innerHTML = '<input type="'+this.state.value+'"/>';
if(this.state.value != "select") $('#selectOption').hide();
}
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="date">Date</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" />
<i className="fa fa-plus-circle icon add" title="Add another choice" onClick={this.addChoice} ></i><i className="fa fa-minus-circle icon remove" onClick={this.removeChoice}
title="Delete this choice"></i>
</div>
<div className="space">
<input type="text" className="inputControl" />
<i className="fa fa-plus-circle icon add" title="Add another choice" onClick={this.addChoice} ></i><i className="fa fa-minus-circle icon remove" onClick={this.removeChoice}
title="Delete this choice"></i>
</div>
</div>
</div>
);
}
});
任何人都可以提出如何添加動態文本框?
讓我來試試呢:) – Dhara