在jQuery Mobile标题中添加一个开关

时间:2013-07-09 01:05:56

标签: jquery mobile header switch-statement

我正在尝试向标头添加开关。它工作正常,但开关在下一行,我希望它在标题右侧

代码:

<div data-role="page" id="moreevents">
    <div data-role="header" data-position="fixed">
        <a href="#defaultclub" data-icon="arrow-l" data-theme="b" onclick="getClubData(curClub)" id="backtoclub">Back</a>
        <h1>All Events</h1>
        <div align="right">
            <select name="switch" id="alleventsswitch" data-role="slider">
            <option value="off">No Past</option>
            <option value="on">Past</option>
            </select>
        </div>
    </div>
</div>

工作示例:

http://jsfiddle.net/Y9ntF/

1 个答案:

答案 0 :(得分:1)

点击此处DEMO http://jsfiddle.net/yeyene/Y9ntF/1/

您需要减少默认h1宽度和边距,以便为switch提供空间。

HTML

<div data-role="page" id="moreevents">
    <div data-role="header" data-position="fixed">
        <a href="#defaultclub" data-icon="arrow-l" data-theme="b" onclick="getClubData(curClub)" id="backtoclub">Back</a>
        <h1 id="myTitle">All Events</h1>
        <span id="mySelect">
            <select name="switch" id="alleventsswitch" data-role="slider">
            <option value="off">No Past</option>
            <option value="on">Past</option>
            </select>
        </span>
    </div>
</div>

CSS

#myTitle{
    float:left;
    width:20%;
    margin: .6em 0 .8em 40%;
}
#mySelect{
    float:right;
    z-index: 1;
}