`

React / Angularjs 字符串(拼接)连接+变量

阅读更多

Angularjs字符串拼接变量很简单,因为里面都是js操作,所以不论是

 

<a ng-href="http://each.sinaapp.com/angular + {{variable}}">

or

<a ng-href="{{'http://each.sinaapp.com/angular'+variable}}">

<a ng-onclick="jump('http://each.sinaapp.com/'+variable)">
<div ng-click="jump('http://each.sinaapp.com/'+variable)">ddd</div>

<button ng-click="jump('http://each.sinaapp.com/'+id)">Jump</button>
<div>jump('http://each.sinaapp.com/{{id}}')</div>

 

 

可以的,而在React里面确有点小小的区别,因为里面的Element后面若有变量不允许双引号包围的。所以

<a href="http://each.sinaapp.com/angular{variable}">

or

<a href="http://each.sinaapp.com/angular"+{variable}>
// 都不可以

// 只能这样
<a href={'http://each.sinaapp.com/angular' + variable}>

or

<a href={'http://each.sinaapp.com/angular' + this.props.username}>
  {this.props.username}
</a>

 

 or 

<i className={"header-help-icon down" + isShowLoginMenu ? ' up' : ''}></i>

 



有疑问或技术交流,扫描公众号一起讨论学习。

更多React在线学习访问:http://each.sinaapp.com/react/index.html

更多实例应用扫码体验:

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics