开发者

How to write HTML that wont be processed by the browser?

I want to create an HTML file which will c开发者_开发知识库ontain HTML snippets that will be used as templates for my page - I will clone them using jquery and will replace parts of them with actual values.

My problem is, that some of those templates contains images, with templated src attribute (The src attribute has invalid value), and the browser tries to load them.

Is there a way to write html that the browser will ignore during loading?


You want to use jQuery Templates http://api.jquery.com/category/plugins/templates/. You can create HTML templates that are wrapped in script tags. These templates will not be loaded until called.

Rich


Hide the snippets initially with css: display:none. Clone it, replace placeholders and then insert into your DOM at the correct place. Then show them: display.block, or use JQuery to show $('#someElement').show();


This is kinda against the purpose of writing html, it's meant to be read by the browser.

You could however replace your src attribute on the image with a data-src attribute which is a valid HTML5 attribute. Then just set the css for the container of the template block to display: none

You can then place the template at the right position and insert src attributes on the images with the value of the data-src attribute causing the image to load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜