[英]Event.target.value not retrieving value properly
This HTML: 此HTML:
<li value="16-May-2017" data-reactid=".0.1.0.0.1.2.2.$16">16test</li>
I'm trying to retrieve the value of, with this React.js code: 我正在尝试使用此React.js代码检索值:
selectDate(event) {
event.preventDefault();
console.log(event.target.value);
if(this.state.whichDate == 0) {
this.state.selectedToDate = event.target.value
this.state.whichDate = 1
} else {
this.state.selectedFromDate = event.target.value
this.state.whichDate = 0
}
}
However, I get "16" printed to console instead of "16-May-2017". 但是,我在控制台上打印的是“ 16”,而不是“ 2017年5月16日”。
I thought it might be printing the text between the tags, but it can't be as I put test there to see... maybe it's not printing anything after the hyphen in the value? 我以为可能是在标签之间打印文本,但是不能这样做,因为我在这里进行了测试以查看...也许在值的连字符后没有打印任何内容?
您想要的是:
console.log(event.target.getAttribute('value'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.