javascript - 动态改变元素的索引
问题描述
我正在尝试做这样的事情:
我按下按钮并弹出窗口,现在这个窗口的索引将为 1,如果我按下另一个按钮,新窗口(div 元素)将出现,但它的索引将为 2。
现在我有了这个函数——点击它使用全局索引变量设置索引,在我的函数结束时,我增加索引变量。但是我没有得到结果——索引变量没有增加(只有在我点击同一个按钮时它才会增加)。有什么解决办法吗?
代码:HTML
<div @click="open(file.name)" class="folder">
<div class="folder-styling">
<div :style="{ 'background-image': 'url(/img/' + file.icon + '.png)' }" class="folder-icon">
</div>
<p>{{file.name}}</p>
</div>
</div>
JS:
open(folder){
var doc = document.getElementById(folder)
doc.style.zIndex = this.$index+1
var tab = document.getElementById('tabs'+folder)
doc.style.display = "block",
tab.style.display = "inline-block",
this.$props.file.active(true)
this.index = this.$index + 1
console.log(this.$index)
}
main.js 文件中的全局变量:
Vue.prototype.$index = 1
解决方案
推荐阅读
- c# - 具有通用实体的 EF Core 双向导航属性
- azure-functions - 在本地调试 Azure Functions
- android - Xamarin Android - 通过 FirebaseApp.InitializeApp 方法而不是通过 google-services.json 获取 FCM 令牌
- django - NoReverseMatch 在/myapp/products/
- javascript - 按数据属性隐藏元素
- maven - 尽管在 pom.xml 中排除了重复的 JAR,但仍被复制
- angular - 如何在ionic3中使用ngx-walkthrough
- c - 星号位置在 C 函数构建中意味着什么?
- asp.net - 将 media_ids 添加到 Twitter API 调用会导致身份验证问题
- regex - 匹配大写单词