javascript - 单击 getElementsByClassName 和 where

标签 javascript jquery angularjs

<a class="contacts" ng-click="contactSelect(contact.userID)">
     <!---->
     <span ng-switch-default="" my-user-status="::contact.userID">Hello World !</span>
     <!---->
     </div>
</a>

我正在使用此代码进行点击:$('.contacts').click();并且它正在工作,但我的问题是我想单击所有标签 a 包含字符串 Hello World!.

最佳答案

您应该能够做任何您想做的事情,而不是通过关注 ng-switch 元素内的字符串,而是通过更改 ng-switch 显示内容并执行其中所有操作的属性你的ng-click并摆脱使用jQuery来实现这一点。

更改 ng-click 以传入整个联系人对象,而不仅仅是用户 ID

<a class="contacts" ng-click="contactSelect(contact)">

然后在 Controller 中,我将假设 ng-switchcontact 对象相关:

var switchValues =['one','two','three'];// if not in this array will use default
$scope.contactSelect = function(contact){
   var userId = contact.userId;
   // do something with the userId

   var switchValue = contact.switchProperty;
   // do something with the switchProperty
    if(switchValues.indexOf(switchValue ) === -1){
       // this will be default case with string "hello world" in the dom
       // do whatever you would have done in the jQuery
    }

}

这非常粗略,因为问题中没有提供太多细节

关于javascript - 单击 getElementsByClassName 和 where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41204749/

相关文章:

javascript - 删除附加的内容并在单击时添加其他内容

javascript - ng-show - 使用服务作为范围参数

javascript - 如何在脚本计数后立即使用 AJAX 从数据库中查看数据?

javascript - 如果我使用 Angular 作为前端,我是否需要使用 ejs 或布局?

javascript - 触发 AngularJS $http promise 的错误条件?

javascript - Jquery加载后改变内容

javascript - 如何为内联元素创建垂直 jQuery 或 CSS slider

javascript - 仅在托管应用程序时出现错误,但在本地主机中则不会出现错误

调色板生成器的 javascript 源代码

jquery - 使用 jQuery Masonry 时 IE 中随机丢失图像