Html 如何在html文档中连接字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44215037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:42:00  来源:igfitidea点击:

How to concatenate string inside html document

htmlangularjsconcatenation

提问by Никола Спа?и?

How can I concatenate string in HTML Attribute. I am using angular controller and in the part where I write some array in HTML (Code is below), I want to give input tag name that is "kolicina" + {{idhrana}} witch is attribute of object jelo.

如何在 HTML 属性中连接字符串。我正在使用角度控制器,在我用 HTML 编写一些数组的部分(代码如下),我想给输入标签名称“kolicina”+ {{idhrana}} 女巫是对象 jelo 的属性。

 <div class = "rezultat" ng-repeat="jelo in hrana | filter:pretrazi_namirnice">
     <div>  {{jelo.naziv}}  </div>
     <div>  {{jelo.energijaKCal}}</div>
     <div>  {{jelo.proteini}}</div>
     <div>  {{jelo.uglj_hidrati}}</div>
     <div>  {{jelo.masti}}</div>
     <div><input type=text nama="kolicina"+{{idhrana}}></div>
     <div><input  type="button"  ng-click = 'dodaj(jelo)' value="Dodaj"></div>
 </div>

回答by Philipp Meissner

You can do it like so:

你可以这样做:

<input type=text name="kolicina{{idhrana}}"></div>

No need to explicitely concatenate it. Also, I think you had a typo with namaversus the name-attribute.

无需明确连接它。另外,我觉得你有一个错字与namaname-attribute。

回答by Himesh Suthar

http://plnkr.co/edit/uJcDZkrGNqzSibpgkTc9?p=preview

http://plnkr.co/edit/uJcDZkrGNqzSibpgkTc9?p=preview

<input type=text name="kolicina {{idhrana}}">

working plnkr for understanding. hope this will help you.

工作 plnkr 以供理解。希望这会帮助你。