ajax的单击事件不触发的选择选项单击、选项、事件、ajax

由网友(暖心向阳)分享简介:我有一个选择列表(#searchHistory)阿贾克斯附:I have a select list(#searchHistory) appended by ajax:var toAppend = '' + eVal + '';$("#s...

我有一个选择列表(#searchHistory)阿贾克斯附:

I have a select list(#searchHistory) appended by ajax:

var toAppend = '<option rel="' + relval + '">' + eVal + '</option>';
$("#searchHistory").append(toAppend);  

和没有注册的选择框单击事件

and there is a click event registered for the select box

 $('#searchHistory option').click( function() {
    var shOpt = $(this);
    var relVal = shOpt.attr('rel');

    alert(relVal);
});

我的问题是,最后一个项目的选择框不会触发click事件!!!!所有其他项目被点击时工作。有趣的是,当我使用prePEND而不是在追加,第一个项目不会触发click事件和所有其他项目做的工作。请注意,选择框被阿贾克斯code填充上方。这意味着,如果我添加另一个到列表框中,则previous非工作项目运作良好,但最近添加的项目仍然无法正常工作。

my problem is that the Last Item of the select box does not fire the click event!!!! all other items are working when clicked. Interestingly when i use a PREPEND instead on APPEND, the first item does not fire the click event and all other items do work. please note that the select box is populated by ajax code above. it means, if i add another to the list box, then the previous non-working item works well but the recently added item still not work.

任何想法,请??? 谢谢

any ideas please ??? thanks

推荐答案

尝试

$('#searchHistory').change( function() {
    var shOpt = $(this).find('option:selected');
    var relVal = shOpt.attr('rel');

    alert(relVal);
});
阅读全文

相关推荐

最新文章