jQuery数据attr没有设置 [英] jQuery data attr not setting

查看:84
本文介绍了jQuery数据attr没有设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来很简单,但我不明白为什么它不起作用。选择器是正确的,但div .faqContent 根本没有使用 data-height 属性进行更新。

This appears very simple but I cannot see why it's not working. The selector is correct however the div .faqContent is simply not being updated with the data-height attribute.

$('.faqItem .faqContent').each(function(){
    var h = $(this).height();
    $(this).data('height',h);
});

我检查过 var h 是否正确,它在colsole.log中正确保持高度。

I have checked that var h is correct, it is in colsole.log as correctly holding the height.

编辑
绝对没有冲突,控制台显示没有错误。

EDIT It's absolutely not conflict, and console shows no errors.

推荐答案

您将无法在元素检查器中看到它,但它在那里,因为jquery在内部设置了数据属性。

You will not be able to see it in the element inspector but it is there as jquery set the data attribute internally.

尝试 console.log($(this).data('height'));

这篇关于jQuery数据attr没有设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆