var id = $(this).parent().attr("data-id");代码中data-id指的是<div class="xzCzIn"> <a href="javascript:void(0)" class="Dels" :data-id="c.id">删除</a> </div>中的data-id还是c.id
时间: 2023-11-03 11:05:52 浏览: 61
代码中的data-id指的是<div class="xzCzIn"> <a href="javascript:void(0)" class="Dels" :data-id="c.id">删除</a> </div>中的c.id。因为通过`$(this).parent().attr("data-id")`获取的是`<div>`标签上的`data-id`属性值,而这个属性是通过Vue.js的动态绑定`:data-id="c.id"`绑定到了`<a>`标签的`c.id`属性上。
相关问题
var id = $(this).parent().attr("data-id");代码中data-id指的是<div class="xzCzIn"> <a href="javascript:void(0)" class="Dels" :data-id="c.id">删除</a> </div>中的data-id还是c.id,需要把var id = $(this).parent().attr("data-id");中的data-id换成c.id吗
是的,需要将`var id = $(this).parent().attr("data-id");`中的`data-id`替换为`c.id`,即`var id = $(this).parent().attr("c.id");`。因为在HTML代码中,`data-id`是Vue.js的动态绑定方式,而在JavaScript代码中,需要直接获取`c.id`的值。
$(this).children()输出的属性是什么
`$(this).children()` 是 jQuery 中的一个方法,用于获取当前元素的所有子元素。该方法返回一个 jQuery 对象,其中包含了所有子元素的元素对象。
如果要获取子元素的属性值,可以使用 jQuery 对象提供的一些方法,例如 `attr()`、`prop()`、`data()` 等。这些方法可以传入一个属性名称作为参数,返回对应属性的值。
以下是一个示例代码,演示如何获取子元素的属性值:
```javascript
// HTML 代码
<div id="parent">
<div class="child" data-value="123">子元素1</div>
<div class="child" data-value="456">子元素2</div>
</div>
// JavaScript 代码
$("#parent").children().each(function() {
var value = $(this).data("value"); // 获取 data-value 属性值
console.log(value); // 输出:123 和 456
});
```
在这个示例代码中,`$(this)` 代表了当前元素,即 `#parent` 元素的一个子元素。`$(this).children()` 返回了 `#parent` 元素的所有子元素,然后使用 `each()` 方法遍历这些子元素,分别获取它们的 `data-value` 属性值。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![js](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)