KendoUI - 不适用于动态添加的元素

时间:2015-12-11 17:37:18

标签: jquery kendo-ui kendo-dropdown

$(document).ready(function() {
  $("select").kendoDropDownList();

});

$( document ).on( "click", "#new", function(){
  $("#container").append('<select><option>New option</option><option>New option 2</option><option>New option 3</option></select>');
});
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2015.3.1111/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2015.3.1111/styles/kendo.material.min.css" />

<script src="//kendo.cdn.telerik.com/2015.3.1111/js/jquery.min.js"></script>
<script src="//kendo.cdn.telerik.com/2015.3.1111/js/kendo.all.min.js"></script>


<div id="container">
  <select>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
  </select>
</div>

<a href="#" id="new">Add More</a>

我是jQuery和KendoUI的新手

如果我直接将KendoUI代码用于元素,它就可以了。但是,如果我动态创建元素并尝试应用,则它无效...

帮助!

  

ONLINE DEMO

HTML

<div id="container">
  <select>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
    <option>lorem ipsum</option>
  </select>
</div>

<a href="#" id="new">Add More</a>

SCRIPT

$(document).ready(function() {
  $("select").kendoDropDownList();

});

$( document ).on( "click", "#new", function(){
  $("#container").append('<select><option>New option</option><option>New option 2</option><option>New option 3</option></select>');
});

1 个答案:

答案 0 :(得分:2)

动态创建元素后,您需要再次将kendoDropDownList绑定到select标记。

$( document ).on( "click", "#new", function(){
  $("#container").append('<select><option>New option</option><option>New option 2</option><option>New option 3</option></select>');
  $("select").kendoDropDownList();
});

http://jsfiddle.net/avz15vsr/3/