jQuery change()警报一键触发6次? [英] jquery change() alert fires 6 times for one click?
问题描述
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屋!