0

每次我尝试加载我的 jQuery 模板时,我都会遇到同样的错误。在准备好文档时,我将项目列表作为 json 列表,并成功运行此代码:

 function add(result) {
            var panel = $('#MainContent_Panel1');
            for (var k = 0; k < result.d.length; k++) {
                $("#template").tmpl(result.d[k]).appendTo("#MainContent_Panel1");

            }

        }

这是我的模板:

   <script id="template" type="text/x-jquery-tmpl"​​​​​​​​​​​​​​​​ >

        <div id ="myID" style="background-color: red">
        <span questionLabelGroup="$i">Question : ${Uid}</span>
        <span questionTextGroup="$i">Hello ${Content}<br /></span>
        <span answerLabelGroup="$i">Answer : </span>
        <input  type='text' questionID="$guid"/>
        <input type='button' Class='addAnswerButton' addQuestionButtonGroup='"$i"' value='Add Question' />
        <hr />
        </div>

        </script>

我不断收到此错误:TypeError: $("#template").tmpl is not a function。任何想法我做错了什么?

4

1 回答 1

3

听起来可能没有加载 jquery 模板插件。您是否包含加载插件的脚本标签?如果是这样,它是否在您的示例中的代码片段被执行之前被加载?

于 2012-09-27T18:36:46.057 回答