【问题标题】:Using javascript/jQuery to access html elements that have ids/attributes dynamically generated with angular js使用 javascript/jQuery 访问 html 元素,这些元素具有使用 Angular js 动态生成的 ids/attributes
【发布时间】:2015-04-07 05:11:14
【问题描述】:

在 jQuery/javascript 中有没有一种方法可以选择一个带有 id 或其他由 AngularJS 动态生成的属性的 html 元素?

例如,我有一个带有使用此角度代码创建的 id 的下拉列表:

ng-attr-id="{{'type-'+($index+1}}"

我想获取 id 为“type-2”的元素的值。但是 javascript 没有在同一页面上找到 id 为“type-2”的元素。

感谢所有建议。

谢谢。

【问题讨论】:

  • 为什么不给它分配一个 ng-model 并通过 Angular 获取值...通常不赞成将 Angular 和 jQuery 混合使用,因为它通常会产生问题。
  • 需要显示更多代码并解释您想要做什么。你可能甚至不需要身份证
  • 你的 JS/jQuery 在哪里?

标签: javascript jquery html angularjs


【解决方案1】:

首先,$index + 1 后面缺少一个 ')'

将此代码更改为

ng-attr-id="{{'type-'+($index+1)}}"

然后尝试:

 $(document).ready(function(){
   alert($("#type-2").html());
});

【讨论】:

    猜你喜欢
    • 2013-06-28
    • 2018-09-11
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 2019-01-10
    • 2014-03-15
    • 2011-01-02
    • 1970-01-01
    相关资源
    最近更新 更多