亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - What is html written in script?
曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新 2017-06-12 09:31:07
0
1
688

I saw that some websites write html in the script tag. Isn't it correct to write js? ?

曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新

reply all(1)
大家講道理

This is a common HTML template in the jQuery era. The code looks like the following

<script id="my-template" type="text/x-custom-template">
    <p class="xxx">
        <p class="yyy">%name%</p>
        <p class="zzz">%value%</p>
    </p>
</script>
The

script tag prevents template content from being displayed on the page. Therefore, when using jQuery to render data, there is no need for HTML string concatenation. Instead, you only need to directly take out the HTML text in the template and use JS to do regular replacement:

var template = document.getElementById("my-template").innerHTML;
var html = template
            .replace(/%name%/, data['name'])
            .replace(/%value%/, data['value']);
// insert HTML...

In this way, you can easily render the JSON data obtained by Ajax into styled HTML text.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template