如何将任意属性添加到HTML标记使用AngularJS [英] How to Add an Arbitrary Attribute to an HTML Tag Using AngularJS

查看:83
本文介绍了如何将任意属性添加到HTML标记使用AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动态地指定某些<按钮> 取值为具有像正确= TRUE 或值 =正确虚假。我看到如何使用
理想情况下这个属性是不可见的,一个用户点击查看源文件。
我的答案通过JavaScript调试器是可见的生活。

现在我将其存储在一个单独的数据结构,并通过其动态由AngularJS构建的ID寻找它:

 < D​​IV的风格=填充顶:5像素级=COL-MD-偏移3NG重复=答案回答>
   <按钮ID =_ answerChoice {{$指数}}
           风格=FONT-SIZE:18像素;
           类=BTN BTN-默认
           NG-点击=selectButton($事件)>           {{回答}}   < /按钮>
< / DIV>


解决方案

纳克带有jQuery的简易版本,所以你可以编写脚本类似

  $('按钮')ATTR(正确的,真正的)。

I need to dynamically designate some <button>s as having a value like correct=true or correct=false. I see how to use Ideally this attribute would be invisible to the a user clicking 'view source.' I can live with the answer being visible via a JavaScript debugger.

Right now I am storing it in a separate data structure and looking it up via the id which is dynamically constructed by AngularJS:

<div style="padding-top: 5px" class="col-md-offset-3" ng-repeat="answer in answers">
   <button id="answerChoice_{{$index}}" 
           style="font-size: 18px;" 
           class="btn btn-default" 
           ng-click="selectButton($event)" >

           {{answer}}

   </button>
</div>

解决方案

ng comes with jquery light version so you can script something like

$('button').attr("correct",true);

这篇关于如何将任意属性添加到HTML标记使用AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆