JQuery函数如何写在kendoui模板中?

How write JQuery function in kendo ui template?

我真的不知道kendo ui支持这个。

我想在 kendo ui 模板中编写一个 JQuery 函数

示例如下

<script type="text/x-kendo-template" id="someId">
#
 $(document).ready(function () {

 $('#textfield1').attr('required');

});
#
<script> 

问题是散列 ("#") 标记给我一个错误,因为 kendo ui 使用散列标记分隔 JavaScript 和 HTML in kendo UI。 那么如何在上面的示例中添加哈希标记。 有人能帮我吗 ??

您需要将每个代码行都放在开头和结尾的#。

#$(document).ready(function () {#
    #$('#textfield1').attr('required');#
 #}); #

来源:http://demos.telerik.com/kendo-ui/templates/expressions

你的语法不正确!这是正确的

这里也是例子

http://demos.telerik.com/kendo-ui/templates/expressions

<script type="text/x-kendo-template" id="someId">

# $(document).ready(function () { #

#  $('#textfield1').attr('required'); #

# });#

<script> 

您可以使用反斜杠作为转义字符:

<script id="javascriptTemplate" type="text/x-kendo-template">
    <h4>#= $("\#theSpan").text()  #</h4>
</script>

DEMO

P.S。我认为您不需要 document.ready,因为 KendoUI 代码(包括模板)依赖于 jQuery,并且仅在文档准备好后运行。