jQuery change()警报一键触发6次? [英] jquery change() alert fires 6 times for one click?

查看:81
本文介绍了jQuery change()警报一键触发6次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery(document).ready(function($)
{
    $('.c5sliderSelect').change(function() 
    {
        alert('change clicked');
    });
});

当我更改选择列表项时,我会收到6条警报.不知道为什么.在这个类名的标记中,我只有一个元素,而选择列表中有10个选项项.

When I change the select list item, I get 6 alerts. Not sure why. I only have one element in the markup with this classname and the select list has 10 option items.

有什么主意为什么警报会针对单个更改事件多次触发?

Any ideas why the alert fires more than once for a single change event?

标记:

<select 
    class="c5sliderSelect" 
    title="Note: only categories which have posts assigned are listed here"> 
    <option value="">Custom Text</option> 
    <option value="164">Blog (10)</option>
    <option value="8">Digital Cameras (3)</option>
    <option value="9">GPS Systems (1)</option>
    <option value="7">Healthy Herbal Teas (1)</option>
    <option value="93">hidden (1)</option>
    <option value="20">iPhone 4s (2)</option>
    <option value="5">Samsung Galaxy (5)</option>
    <option value="4">Smart Phones (5)</option>
    <option value="1">Uncategorized (7)</option>
</select>

我要在此处执行的操作是,当所选项目的值为"

What I'm trying to do here is to hide an unrelated div when the selected item's value is ""

推荐答案

尝试使用alert以外的其他方式. alert对焦点有可怕的影响,当然change事件与focus有关.尝试console.log或类似版本.

Try using something other than alert. alert has horrible effects on focus, and of course the change event relates to focus. Try console.log or similar.

例如,使用您的标记的此实时示例显示仅触发了一个change事件.

For instance, this live example using your markup shows only a single change event being fired.

这篇关于jQuery change()警报一键触发6次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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