在 jQuery/javascript 中有没有一种方法可以选择具有 id 或 AngularJS 动态生成的其他属性的 html 元素?
例如,我有一个下拉列表,其中包含使用此 Angular 代码创建的 id:
ng-attr-id="{{'type-'+($index+1}}"
我想获取 ID 为“type-2”的元素的值。但是 javascript 在同一页面上找不到 ID 为“type-2”的元素。
感谢所有建议。
谢谢。
最佳答案
首先,您在 $index + 1
将此代码更改为
ng-attr-id="{{'type-'+($index+1)}}"
然后尝试:
$(document).ready(function(){
alert($("#type-2").html());
});
关于javascript - 使用 javascript/jQuery 访问具有使用 angular js 动态生成的 ids/属性的 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29479637/