I have the following selector:
$('#terminal-template').text()
and following jsp page fragment inside the body :
<script type="text/template" id="terminal-template">
<li data-terminal-id="{{ id }}" class="{{ clazz2 }}">
<label>
<input type="checkbox" name="terminal" class="{{ clazz }}" data-terminal-id="{{ id }}" />
<a href="#" title="" class="image"><img
src="getSmallThumbnail/{{imageId}}"
alt=""/></a>
<h3>{{ name }}
<small>{{ place }}</small>
</h3>
<p class="count">Проходимость: <span>{{ count }}</span> чел./час</p>
<p class="count">Стоимость: <span>{{ amount }}</span> руб./час</p>
<p class="count">Количество свободных слотов: <span>{{ numberOfEmptyCase }}</span> </p>
</label>
</li>
</script>
In IE $('#terminal-template').text()
it returns empty ( ""
)
but in chrome - it works properly and returns
"
<li data-terminal-id="{{ id }}" class="{{ clazz2 }}">
<label>
<input type="checkbox" name="terminal" class="{{ clazz }}" data-terminal-id="{{ id }}" />
<a href="#" title="" class="image"><img
src="getSmallThumbnail/{{imageId}}"
alt=""/></a>
<h3>{{ name }}
<small>{{ place }}</small>
</h3>
<p class="count">Проходимость: <span>{{ count }}</span> чел./час</p>
<p class="count">Стоимость: <span>{{ amount }}</span> руб./час</p>
<p class="count">Количество свободных слотов: <span>{{ numberOfEmptyCase }}</span> </p>
</label>
</li>
"
When fetching HTML from inside a template, stored inside a dummy script block, you should always use .html()
, not text()
.
eg this will work on all browsers:
var html = $('#terminal-template').html();
I am actually surprised that text()
returns anything on any browser, but I guess Google though that might be useful. Technically script content is "text", but that was not standardised across all browsers so is best avoided. html()
is guaranteed to return the innerHTML
property so will always work on all browsers
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.