onClick() 不适用于 dropkick.js 中的目标元素
我正在使用超级棒的 dropkick.js,但我注意到一件小事;使用 jquery onClick() 事件来定位列表中的元素似乎是不可能的。
我尝试过使用第 n 个子选择器(通过 css 效果很好)和警报并停止传播和各种不同的方法;但由于某种原因,每当我单击列表中的某个元素时,它都不会听到我已单击该元素,并且不会继续执行我要求的操作。这是我的代码:
<div class="dk_options" style="top: 34px;">
<ul class="dk_options_inner">
<li class="" style=""><a data-dk-dropdown-value="">PICK A PRINT</a></li>
<li class="digital dk_option_current" style=""><a data-dk-dropdown-value="digital">Giclee Print</a></li>
<li class="screen"><a data-dk-dropdown-value="screen">Screen Print</a></li>
</ul>
</div>
这是脚本:
<script type="text/javascript">
$(document).ready(function() {
$('.screen-price').hide();
$('.screen').click(function(){
$('.digital-price').hide();
$('.screen-price').show();
return false;
});
$('.digital').click(function(){
$('.screen-price').hide();
$('.digital-price').show();
return false;
});
$('.add-to-cart').click(function(){
return false;
});
});
</script>
我不确定交易是什么;我尝试过各种解决方案。请告诉我。
I'm using the super awesome dropkick.js, but i'm noticing one small thing; targeting the elements within it's lists doesn't seem possible with jquery onClick() event.
I've tried using nth child selectors (which work great via css) and alerts and stop propigation and all sorts of different methods; but for some reason, whenever I click an eleement in the list, it doesn't hear that I've clicked that element and doesn't proceed to do what I'm asking it to. Here's my code:
<div class="dk_options" style="top: 34px;">
<ul class="dk_options_inner">
<li class="" style=""><a data-dk-dropdown-value="">PICK A PRINT</a></li>
<li class="digital dk_option_current" style=""><a data-dk-dropdown-value="digital">Giclee Print</a></li>
<li class="screen"><a data-dk-dropdown-value="screen">Screen Print</a></li>
</ul>
</div>
And here's the script:
<script type="text/javascript">
$(document).ready(function() {
$('.screen-price').hide();
$('.screen').click(function(){
$('.digital-price').hide();
$('.screen-price').show();
return false;
});
$('.digital').click(function(){
$('.screen-price').hide();
$('.digital-price').show();
return false;
});
$('.add-to-cart').click(function(){
return false;
});
});
</script>
I'm not sure what the deal is; I've tried all sorts of solutions. Please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的。我想我已经明白了这一点。我不知道为什么它会这样工作,但确实如此。
因此,为了定位我的菜单,我必须:
1)专门调用菜单;在本例中,它是 .price-menu
2) 确保我使用 .dropkick 调用它
3) 使用
change: function()
语句4) 将它们全部串在一起,看起来像这样
:出于某种原因,执行我想要它执行的操作的代码在整个事情之外,但仍在脚本本身内;一探究竟:
});
这就是窍门。我不确定到底为什么,但它确实有效。
有人对它的工作原理有任何见解或者愿意向我解释吗?
另外,非常感谢所有发布到此帖子的人 - 我很感激 :c)
干杯!
杰成
Okay. I think I've figured this out. I'm not sure why it's working like this, but it is.
So, in order to target my menus, I have to:
1) Call the menu specifically; in this case it's .price-menu
2) Make sure I call it using .dropkick
3) Use a
change: function()
statement4) String it all together to look something like this:
Now, for some reason, the code that does what I want it to do is outside of this whole thing, but still within the scrip itsefl; check it out:
});
That does the trick. I'm not sure why exactly, but it works.
Anyone have any insight on how this works or would care to explain it to me?
Also, thank you so much to everyone who's posted to this thread - I appreciate it :c)
Cheers!
JC