Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $.html()返回未定义的值?_Javascript_Mustache - Fatal编程技术网

Javascript $.html()返回未定义的值?

Javascript $.html()返回未定义的值?,javascript,mustache,Javascript,Mustache,尽管存在ID为“quick template”的脚本元素,这行代码($(“#quick template”).html();)始终返回未定义的。我不知道问题出在哪里。你们有谁经历过这样的事情吗?任何帮助都将不胜感激 index.html: <script id="quiz-template" type="text/html"> <h1>{{question}}</h1> <hr> <p class="right" style="d

尽管存在ID为“quick template”的脚本元素,这行代码($(“#quick template”).html();)始终返回未定义的。我不知道问题出在哪里。你们有谁经历过这样的事情吗?任何帮助都将不胜感激

index.html:

<script id="quiz-template" type="text/html">
  <h1>{{question}}</h1>
  <hr>
  <p class="right" style="display: none;">Richtig!</p>
  <p class="wrong" style="display: none;">{{explanation}}</p>
  <form id="answerForm" action="javascript:submitValue();">
    {{#possibleAnswers}}
    <div><label><input type="radio" name="answer" value="{{.}}">{{.}}</label></div>
    {{/possibleAnswers}}
    <input type="submit" value="Antwort bestätigen">
  </form>
</script>

确保在加载文档时执行showPage功能。你查过了吗

编辑: 我认为你不能得到html的原因是因为“script”标签。我建议使用以下两种方法之一:

1) Simple:
<textarea id="name" style="display:none">
        ... templates ...
</textarea>


2) Valid XHTML 1.1 (using CDATA):
<p style="display:none"><textarea id="name" rows="0" cols="0"><![CDATA[
        ... templates ...
]]></textarea></p>


3) Valid XHTML 1.1 (using comments; suggested):
<p style="display:none"><textarea id="name" rows="0" cols="0"><!--
        ... templates ...
--></textarea></p>
1)简单:
... 模板。。。
2) 有效的XHTML 1.1(使用CDATA):

3) 有效的XHTML 1.1(使用注释;建议):


是否确实在加载元素后执行脚本?在浏览器控制台中,可以尝试
$(“#测验模板”).html()
我在调试时执行了此操作,但返回未定义。但是我不知道你为什么可以试试
$(“#测验模板”)。在控制台中,我会试试。
1) Simple:
<textarea id="name" style="display:none">
        ... templates ...
</textarea>


2) Valid XHTML 1.1 (using CDATA):
<p style="display:none"><textarea id="name" rows="0" cols="0"><![CDATA[
        ... templates ...
]]></textarea></p>


3) Valid XHTML 1.1 (using comments; suggested):
<p style="display:none"><textarea id="name" rows="0" cols="0"><!--
        ... templates ...
--></textarea></p>