jquery.tmpl templates break XHTML-validation
I've document with the following doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xm开发者_如何学Golns="http://www.w3.org/1999/xhtml" lang="ru">
Templates are declared as following:
<script id="tmpl-periods-options" type="text/x-jquery-tmpl">
{{each plans_array}}
<label><input type="radio" value="${$value.id}" name="pf-periods" {{if $value.selected}}checked="checked" {{/if}} />${$value.title}</label>
{{/each}}
</script>
http://validator.w3.org/ shows me errors about html code which is declared inside <script>
tag.
Is there any solution?
Normal JavaScript techniques don't work as this isn't JavaScript; simply wrapping the template in //<![CDATA[ ... //]]>
or //<!-- ... //-->
just causes worse problems.
As suggested in this blog post, it seems like the best options are either use HTML 5 or place the template in an external file and include that.
$(document).ready(function() {
$.get('template.html', function(content) {
$.template('template name', content);
});
});
精彩评论