2014-06-24 43 views
0

在jquery mobile中,我尝试用一​​些按钮替换我的标题。我使用jquery的html()函数来完成它。jquery html();无按钮样式

的问题是从按钮的图标会丢失,而且看起来不像原来的div ..

我怎样才能解决呢? Fiddle

HTML

<div data-role="page" id="index"> 
     <div id="header" data-theme="b" data-role="header"> 
      <h1>replace this with some buttons</h1> 
     </div> 

     <div data-role="content"> 
      <div id="map"></div> 
     </div> 
</div> 

<!-- div to instert--> 
<span id="downBut"><center> 
    <button type="submit" id="down" style="width: 110px" data-mini="true" data-theme="a" data-transition="pop" data-icon="carat-d">Download</button> 
    <button type="submit" id="down" style="width: 110px" data-mini="true" data-theme="a" data-transition="pop" data-icon="delete">cancel</button> 
</center></span> 

的Javascript

// make the from header buttons 
$("#header").html($("#downBut")); 

的CSS

.ui-header { 
    height: 40px; 
} 

.ui-content { 
    position: absolute; 
    top: 40px; 
    right: 0; 
    bottom: 0; 
    left: 0; 
    padding: 0 !important; 
    margin: 0; 
} 
h1 { 
    margin: 0 auto; 
} 
+0

你有相同的id'down'和不相同的造型两个按钮。将它更改为每个按钮的不同ID,或者改为给它们分类。 – urbz

回答

2

你必须拨打createheader股利用按钮替换html后。

$('#header').html($('#downBut')); 
$('#header').trigger('create'); 

Working JSFiddle

+1

这是因为这些按钮最初是在'data-role =“page”'div之外的,所以它们在第一次创建页面时并未被jQuery mobile“增强”。 – xdumaine

+0

正是我想要的。谢谢 –

+0

很高兴帮助你:) –