gpt4 book ai didi

javascript - 如何通过javascript改变ng-click状态?

转载 作者:行者123 更新时间:2023-11-28 06:44:35 25 4
gpt4 key购买 nike

我需要让代码在条件为真时运行

if document.getElementByClass('toggle').style.visibility == 'visible'

应该就像在我的页面中写的那样

ng-click="toggle = !toggle"

但是如何在我的 javascript 文件中选择切换状态?

编辑:更多信息

div(ng-controller='ViewsCtrl', ng-class="toggle ? 'nav-open' : 'nav'")
.container
.logo
img(src='images/logo.png')
span Motto

ul(ng-class="toggle ? 'menu-open' : 'menu'")
li
a(ng-click="changeView('home')") Home
li
a(ng-click="changeView('products')") Products

button.toggle(ng-click='toggle = !toggle') Menu

Controller

appControllers.controller 'ViewsCtrl', [
'$scope'
'$location'

Ctrl = ($scope, $location) ->

$scope.changeView = (view) ->
$location.path view
if document.getElementByClass('toggle').style.visibility == 'visible'
$scope.toggle = !toggle
return

return

]

最佳答案

看这个:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<input type="button" ng-click="toggle = !toggle" value="{{toggle?' Hide':' Show'}}"/>
<div ng-show="toggle">shown</div>
</div>

关于javascript - 如何通过javascript改变ng-click状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33503075/

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