Why is browser returning error “TypeError: this._input is null” in Firefox (and similar in Chrome) when using handlebars.js?

*爱你&永不变心* 提交于 2019-12-01 08:10:13

That error means that #entry-template isn't in the DOM when you try to use it:

var source = $("#entry-template").html(); // There is no #entry-template in the DOM here
var template = Handlebars.compile(source);

That means that you end up trying to compile undefined as a Handlebars template and that doesn't work. You can see the error by running this:

http://jsfiddle.net/ambiguous/LprDR/

with your console open.

The jsfiddle works because you have all your code running after the DOM has been loaded, that's the default jsfiddle behavior.

You probably have a load order problem in your real code, try wrapping it in a $(function() { /*...*/ }) wrapper.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!