由于某些原因,当我尝试将JavaScript输入HTML部分的angle部分时,它不起作用。我正在用Thymeleaf。
这是HTML部分:
<button className="btn btn-info" onClick={this.displayInfo}>Click for info about {firstName[i]}</button>
因此,在这种情况下,它不起作用并返回错误:
unexpected error (type=Internal Server Error, status=500) Exception parsing document
如果我将onClick={this.displayInfo}其删除。
onClick={this.displayInfo}
我的功能:
displayInfo(){ console.log("it worked"); } The render() function: render(){ var {number, firstName, lastName} = this.state; var rows = []; for (var i in number) { rows[i] = (<tr> <td>{number[i]}</td> <td>{firstName[i]}</td> <td>{lastName[i]}</td> <td><button className="btn btn-info" onClick={this.displayInfo()}>Click for info about {firstName[i]}</button></td> </tr>); } var headers = <tr><th>Number</th><th>First Name</th><th>Last Name</th><th>Extra Info</th></tr>; return (<table className="table table-bordered"> <thead>{headers}</thead> <tbody>{rows}</tbody> </table>); }
我收到错误消息是因为Thyemleaf认为我正在输入HTML:我刚刚添加了以下内容:
/*<![CDATA[*/ ... /*]]>*/