Javascript jQuery在HTML模板中找不到元素
我有一个telerik KendoUI模板,我将其加载到jQuery对象中。这是有效的Javascript jQuery在HTML模板中找不到元素,javascript,jquery,telerik,Javascript,Jquery,Telerik,我有一个telerik KendoUI模板,我将其加载到jQuery对象中。这是有效的 <script type="text/x-kendo-template" id="customKeywordsEditorPopup"> Custom Keywords <input style="width:100%" id="inpKeywords"/> </script> 不幸的是,$(popupHtml).find('#inpKeywords')没
<script type="text/x-kendo-template" id="customKeywordsEditorPopup">
Custom Keywords
<input style="width:100%" id="inpKeywords"/>
</script>
不幸的是,$(popupHtml).find('#inpKeywords')没有返回实际的元素。它应该引用输入
你知道为什么这样不行吗
$(popupHtml).find('#inpKeywords').length
返回0,因为
标记中没有元素。
标记内的文本不会呈现为html
为了让你的模板变成html,你必须通过剑道传递它,把它作为html传递给你选择的容器,最后你可以用你的id选择器选择它
var template = kendo.template($("#customKeywordsEditorPopup").html());
$("#SomeContainer").html(template({}));
var input = $("#inpKeywords");
演示
var templateText=$(“#customKeywordsEditorPopup”).text();
var template=kendo.template(templateText);
$(“#SomeContainer”).html(模板({}));
var输入=$(“#输入关键字”);
input.val('Some value')代码>
自定义关键字
var template = kendo.template($("#customKeywordsEditorPopup").html());
$("#SomeContainer").html(template({}));
var input = $("#inpKeywords");