【发布时间】:2021-03-30 02:35:01
【问题描述】:
我想使用数据选择器写入全局变量。这甚至可能吗? (请温柔,我的经验很浅:)
var one = 0;
var two = 0;
var three = 0;
$("a[data-typ]").click(function() {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
$(this).data("typ").toString--;
} else {
$(this).addClass('active');
$(this).data("typ").toString++;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a data-typ='one'>One</a>
<a data-typ='two'>Two</a>
<a data-typ='three'>Three</a>
【问题讨论】:
标签: jquery jquery-selectors global-variables increment decrement