jQuery“.on('click',...)”不适用于LET变量声明。但作品VAR [英] jQuery ".on( 'click' ,....)" does not work with LET variable declaration. But works VAR
问题描述
这是一个jQuery的bug吗?我有一个简单的点击事件。当我使用LET声明一些带有图像链接的变量时,click事件停止在我的ipad(chrome)上工作。当我切换到LET所有作品。
PS:我有同样的代码的另一个问题,但这是完全不同的。
//当我使用VAR.on('click',....)//可以移动。有了LET,它就没有了。imageLink25 =http://s020.radikal.ru/i709/1701/58/89fe5a582b92.png;让imageLink50 =http://i056.radikal.ru/1701/3e /0c7dcfd4956b.png\";let imageLink80 =http://s011.radikal.ru/i318/1701/56/48fc3db701a0.png\";$('.size-list-item').on('click touchend', function(event){event.preventDefault(); $(。size-list-item)。removeClass('active'); $(this).toggleClass('active');});
.active {font-size:25px;}
< script src =https://ajax.googleapis.com/ajax/libs /jquery/2.1.1/jquery.min.js\"></script><div class =menu-list size-list-items> < a class =size-list-itemdata-type =25m2href =#000onclick =void(0)>25μm2< / a> < a class =size-list-item activedata-type =50m2href =#000onclick =void(0)>50μm2< / a> < a class =size-list-itemdata-type =80m2href =#000onclick =void(0)>80м2< / a>< / div> $ c $
块范围。在你的情况下,如果它们不在jQuery块中,你不能使用这三个let变量。
这里有一个链接可以很好地解释var,let和const之间的区别。
https://www.sitepoint.com / prepared-ecmascript-6-let-const /
Is this a jquery bug? I have a simple click event. When I use LET to declare some variables with image links, the click event stops working on my ipad (chrome). When I switch to LET all works.
PS: I had another question with the same code but this is completely different.
// WHEN I USE "VAR" ".on( 'click' ,....)"
// works on mobile. With "LET" it does not.
let imageLink25 = "http://s020.radikal.ru/i709/1701/58/89fe5a582b92.png ";
let imageLink50 = "http: //i056.radikal.ru/1701/3e/0c7dcfd4956b.png";
let imageLink80 = "http://s011.radikal.ru/i318/1701/56/48fc3db701a0.png";
$('.size-list-item').on('click touchend', function(event) {
event.preventDefault();
$(".size-list-item").removeClass('active');
$(this).toggleClass('active');
});
.active {
font-size: 25px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="menu-list size-list-items">
<a class="size-list-item" data-type="25m2" href="#000" onclick="void(0)">25м2</a>
<a class="size-list-item active" data-type="50m2" href="#000" onclick="void(0)">50м2</a>
<a class="size-list-item" data-type="80m2" href="#000" onclick="void(0)">80м2</a>
</div>
The let variables is only available in it's block scope. In your case, you can't use the three let variables if they are outside the jQuery block.
Here's a link that explain well the difference between var, let and const.
https://www.sitepoint.com/preparing-ecmascript-6-let-const/
这篇关于jQuery“.on('click',...)”不适用于LET变量声明。但作品VAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!