$(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代码用于元素,它就可以了。但是,如果我动态创建元素并尝试应用,则它无效...
请帮助!
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>');
});
答案 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();
});