简体   繁体   English

下划线模板中未应用jQuery Mobile CSS样式

[英]jQuery mobile css styles not being applied in underscore template

I am trying to use jQueryMobile styling on elements inside of an underscore template. 我正在尝试在下划线模板内部的元素上使用jQueryMobile样式。 It seems like the styling should get applied as it shows up in the computed styles but it is not being applied. 似乎应该应用样式,因为它以计算的样式显示,但是没有被应用。 On the other hand, my own CSS definition does get applied. 另一方面,我自己的CSS定义确实适用。 Please can anyone tell me what I am doing wrong here? 请有人能告诉我我在做什么错吗?

Underscore Template: 下划线模板:

<script type="text/template" id="test-template">
    <!-- jQueryMobile Styling does not work here... -->
    <a href="#" id="button2" data-role="button" data-icon="arrow-r" data-iconpos="right">Button 2 (jquery style doesn't work)</a>
    <a href="#" id="button3" data-role="button" data-icon="arrow-r" data-iconpos="right">Button 2 (local css style works)</a>
</script>

JavaScript: JavaScript的:

$("#app-content").html(_.template($('#test-template').html()));

CSS: CSS:

#button3 {
    background-color: red;
}

Please see my jsfiddle here: http://jsfiddle.net/DanielBank/WJzTn/ 请在这里查看我的jsfiddle: http : //jsfiddle.net/DanielBank/WJzTn/

Inheritly, jQuery Mobile doesn't apply styles to dynamically injected elements. 继承地,jQuery Mobile不会将样式应用于动态注入的元素。 You will need to call .trigger('create') on the elements to create jQuery mobile based elements. 您将需要在元素上调用.trigger('create')来创建基于jQuery mobile的元素。

$("#app-content").html(_.template($('#test-template').html())).trigger('create')

Will ensure that the buttons receive the proper styles. 将确保按钮收到正确的样式。

As usual, Here's the working jsFiddle 和往常一样, 这是工作中的jsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM