开发者

How do I embed data into jQuery template attribute

开发者 https://www.devze.com 2023-04-04 06:04 出处:网络
I have the following jQuery-tmpl template: <script id=\"month-template\" type=\"text/x-jquery-tmpl\">

I have the following jQuery-tmpl template:

<script id="month-template" type="text/x-jquery-tmpl">
    <div style="width:${width};开发者_如何学JAVA">
        <div>Hello</div>
    </div>
</script>

It is used by the following script:

$("#month-template").tmpl({"width":30}).appendTo($("#containerId"));

I expect to see this output:

<div style="width:30;">
    <div>Hello</div>
</div>

But I get this:

<div style="">
    <div>Hello</div>
</div>

Is there some special way to embed attribute values in a template? I am new to tmpl - maybe I have missed something obvious.


Use 30px instead of 30.

jQuery automatically converts integers to the correct CSS units when using .css() but since it's a template (not CSS-specific) you need to specify the units yourself.

0

精彩评论

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