2012-11-05 23 views
7

可能重複:
How to outsource a template js to a different file when using Handlebars.js訪問與src屬性的腳本標記的內容(包括模板)

我使用handlebears。他們建議,包括在文件人體模板是這樣的:

<script id="entry-template" type="text/x-handlebars-template"> 
    template content 
</script> 

我想通過src屬性使用模板內容和存儲我的模板在單獨的文件(的質量)。

<script src="/path/to/my.template" id="entry-template" type="text/x-handlebars-template"></script> 

問題是如何訪問它的內容?

$('script#entry-template').html() //returns "" 
$('script#entry-template').text() //returns "" 
+0

你可以只是做一個Ajax獲取文件的內容? – Shmiddty

+0

Thanx。沒有通過搜索找到 –

+0

這個想法是使用瀏覽器的標準機制。當它滿足src屬性的腳本標記時,它會加載它。或不?我通過執行$('head')來測試它。append('