我有一个100按钮,点击每个按钮显示其对应的炸弹框,带有javascript和angular
一个按钮对应一个提示框,每个框有不同的外壳;虽然实现了所需的功能,但是我的代码太复杂了,没有简单的方法。我该怎么办?这是我的密码我有一个100按钮,点击每个按钮显示其对应的炸弹框,带有javascript和angular,javascript,angularjs,Javascript,Angularjs,一个按钮对应一个提示框,每个框有不同的外壳;虽然实现了所需的功能,但是我的代码太复杂了,没有简单的方法。我该怎么办?这是我的密码 <--html button--> <a href="" ng-click="showRulePop(1)">button1</a> <a href="" ng-click="showRulePop(2)">button2</a> ... <a href="" ng-click="showRuleP
<--html button-->
<a href="" ng-click="showRulePop(1)">button1</a>
<a href="" ng-click="showRulePop(2)">button2</a>
...
<a href="" ng-click="showRulePop(100)">button100</a>
<--html pop box-->
<div class="note1" style="display:none;">
<img class="title-css" src="note1.png">
<p class="one">note1</p>
</div>
...
<div class="note100" style="display:none;">
<img class="title-css" src="note100.png">
<p class="one">note100</p>
</div>
<--angular js-->
$scope.showRulePop = function(index) {
for(var i=1;i<=8;i++) {
$('.note'+i).hide();
}
$('.note'+index).show();
};
...
注1
...
注100
$scope.showRulePop=函数(索引){
对于(var i=1;i首先,不要使用jQuery,除非您在angular jQuery的指令级别中与此无关
首先,让我们使用一个简单的ng重复来消除链接部分:
<--html button-->
<div ng-repeat="button in buttons">
<a href="" ng-click="showRulePop(i)">{{button.label[i]}}</a>
</div>
// JS in the controller
$scope.buttons = [{
label:'button1'
},{label:'button2'}];
仅此而已,不需要jQuery。什么是炸弹箱?也许可以查看并编辑您的问题。请为您的问题添加详细信息,并添加一些您尝试执行的操作的基本代码。该问题的格式不正确,请选中“添加有关问题的更多详细信息”,如您尝试过的内容、您引用的代码等。非常酷!但我不太喜欢您了解了,我需要给button100写信,比如$scope.buttons?@Phoebe是的,我不确定你的100个按钮是“人造”的还是根据一些数据生成的。
<div class="{{currentnote.class}}" ng-if="currentNote">
<img class="title-css" src="{{currentNote.img}}">
<p class="one">{{currentNote.content}}</p>
</div>
<!-- show 1 to 8 if note current note selected -->
<div ng-repeat="button in buttons1To8" ng-if="!currentNote">
<div class="{{button.note.class}}">
<img class="title-css" src="{{button.note.img}}">
<p class="one">{{button.note.content}}</p>
</div>
</div>
$scope.buttons = [{
label:'button1'
note:{class:'note1', img:'note1.png', content:'note1'//assuming no HTML or you' ll need something more
}},{label:'button2', note:{...}}, ...];
$scope.showRulePop = function(index){
$scope.currentNote = $scope.buttons[index].note;
}
$scope.buttons1To8 = $scope.buttons.slice(0, 8);//0 to 7 in fact