Javascript 在动态创建的div上设置服务器值的下拉列表

Javascript 在动态创建的div上设置服务器值的下拉列表,javascript,jquery,html,Javascript,Jquery,Html,我在使用编辑表单设置动态创建的div中的下拉列表值时遇到问题 document.getElementById("edit-entry").innerHTML = ""; var div = document.createElement('div'); div.className = 'edit'; div.innerHTML = "form html"; document.getElementById('edit-entry').appendChild(div); 在html中是 在控制台上

我在使用编辑表单设置动态创建的div中的下拉列表值时遇到问题

document.getElementById("edit-entry").innerHTML = "";
var div = document.createElement('div');
div.className = 'edit';
div.innerHTML =  "form html";
document.getElementById('edit-entry').appendChild(div);
在html中是


在控制台上,它正在工作sel-change-app.val9;但是当我试图在appendChild下或者使用$function{}时,仍然没有改变。如何检查div是否准备好设置值?当我调试时,我看到sel-change-app比div慢,couse-list来自服务器

希望这对你有帮助

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('select#sel').find('option').each(function() {
            var t=$(this).val();
            $("#mySelect").append(t+"<br>");
        });
    }); 
    </script>
</head>
<body>
    <select id="sel" name="sel">
        <option value="o1">1</option>
        <option value="o2">1</option>
        <option value="o3">1</option>
        <option value="o4">1</option>
    </select>
    <div id="mySelect"></div>
</body>
</html>

为什么不在document.getElementById'edit-entry'.appendChilddiv;?-另一种选择是使用加法来更好地理解;因为它不起作用。我试过了,我认为它的couse sel change应用程序来自函数,所以当我设置value.document.getElementById'edit-entry'.appendChilddiv;jQuery'edit-entry div'.textjQuerysel-change-app.val7;return[object]表单没有显示它更难,因为在我写的时候,列表是从服务器获取的,所以我需要等到它获取时,我想我需要使用回调:/
<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('select#sel').find('option').each(function() {
            var t=$(this).val();
            $("#mySelect").append(t+"<br>");
        });
    }); 
    </script>
</head>
<body>
    <select id="sel" name="sel">
        <option value="o1">1</option>
        <option value="o2">1</option>
        <option value="o3">1</option>
        <option value="o4">1</option>
    </select>
    <div id="mySelect"></div>
</body>
</html>