DropdownList使用Jquery为每个第一次没有处理更改功能

时间:2013-12-28 17:31:57

标签: jquery

<select id="ddlValidationList1">  
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>

<select id="ddlValidationList2">    
</select>

$('#ddlValidationList1').bind('paste cut change keyup', function (e) {
    setTimeout(function () {
        var ddlValidationList = $('#ddlValidationList2');            
                ddlValidationList.append(
                $('<option></option>').html("EmailAddress")
                );
    }, 100);
    $("#ddlValidationList2 option").each(function () {
        alert("hello");            
    });
});

Fiddle

第一次执行更改功能"ddlValidationList2"时,

foreach "ddlValidationList1"功能无效。

1 个答案:

答案 0 :(得分:0)

您的setTimeOut函数会导致此更新fiddle

$('#ddlValidationList1').bind('paste cut change keyup', function (e) {

            var ddlValidationList = $('#ddlValidationList2');            
                    ddlValidationList.append(
                    $('<option></option>').html("Hi")
                    );

        $("#ddlValidationList2 option").each(function () {
            alert("hello");            
        });
    });