开发者

Styling the controlgroup buttons in Jquery Mobile

I have a controlgroup with grouping 3 radio buttons to look like buttons, and what I want to do is to to colour the button on click of each one. Clicking the "Red" will change the colour of the button to "Red"

开发者_StackOverflow中文版

The code is below

<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
    <input type="radio" name="rd1" id="rd1" value="R" />
    <label for="rd1">Red</label>
    <input type="radio" name="rd2" id="rd2" value="G" />
    <label for="rd2">Green</label>
    <input type="radio" name="rd3" id="rd3" value="B" />
    <label for="rd3">Blue</label>
</fieldset>

Can somebody please help me on this.


Live Example:

  • http://jsfiddle.net/phillpafford/fAYEw/5/

JS

$('input[name=rdColor]').change(function() {
    $(this).next().addClass($(this).val());
});

HTML

<div data-role="page" id="home"> 
    <div data-role="content"> 
        <div data-role="fieldcontain">
            <fieldset data-role="controlgroup" data-type="horizontal">
                <input type="radio" name="rdColor" id="rd1" value="R" />
                <label for="rd1">Red</label>
                <input type="radio" name="rdColor" id="rd2" value="G" />
                <label for="rd2">Green</label>
                <input type="radio" name="rdColor" id="rd3" value="B" />
                <label for="rd3">Blue</label>
            </fieldset>
        </div>
    </div>
</div>

CSS

.R {
    background:red;  
}

.B {
    background:blue;
}

.G {
    background:green;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜