gpt4 book ai didi

javascript - 如何通过 jquery 访问 View 中动态添加的元素

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:17:40 26 4
gpt4 key购买 nike

我想访问和修改加载了 Angular View 的元素。我似乎做不到,但是该元素在控制台中输出得很好。

布局

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
</head>
<body data-ng-app="myapp">
<div class="wrap">
<div class="header"></div>
<div class="content">
<div data-ng-view=""></div>
</div>
</div>
<script type="text/javascript" src="/content/plugins/jquery/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="/content/plugins/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="/content/plugins/pxgradient/pxgradient-1.0.2.jquery.js"></script>
<script type="text/javascript" src="/content/plugins/angularjs/angular.js"></script>
<script type="text/javascript" src="/content/plugins/angularjs/angular-route.js"></script>
<script type="text/javascript" src="/content/plugins/angularjs/angular-animate.js"></script>
<script type="text/javascript" src="/app/app.js"></script>
<script type="text/javascript" src="/content/js/main.js"></script>
</body>
</html>

查看

<div class="home">
<h1 class="gradient">Transformation is comming</h1>
</div>

Javascript

$(function () {
var element = $('.gradient');

console.log(element); // this works

element.css('color', 'red'); // this does not
});

最佳答案

好的,我想我有一个解决方案,试试这个:

app.run(function ($rootScope) {
$rootScope.$on('$viewContentLoaded', function () {
$('.gradient').css('color', 'red');
});
});

关于javascript - 如何通过 jquery 访问 View 中动态添加的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22455701/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com