jquery-mobile/docs/forms/forms-radiobuttons.html
2010-10-14 17:42:12 -04:00

68 lines
No EOL
3.1 KiB
HTML
Executable file

<!DOCTYPE html>
<html>
<head>
<title>jQuery Mobile Docs - Forms</title>
<link rel="stylesheet" href="../../themes/default" />
<script type="text/javascript" src="../../js/all"></script>
<script type="text/javascript" src="../docs/docs.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Radio buttons</h1>
</div><!-- /header -->
<div data-role="content">
<form action="#" method="get">
<h2>Radio buttons</h2>
<p>Radio buttons are used to provide a list of options where only a single item can be selected. Traditional desktop radio buttons are not optimized for touch input so in jQuery Mobile, we style the <code>label</code> for the radio buttons so they are larger and look clickable. A custom set of icons are added to the label to provide visual feedback.</p>
<p>To add a set of radiobuttons to your page, start with an <code>select</code> with two options. The first option will be styled as the "on" state switch and the second will be styled as the "off" state so write your options in the correct order. Set the <code>for</code> attribute of the <code>label</code> to match the ID of the <code>input</code> so they are semantically associated and wrap them in a <code>div</code> with the <code>data-role="fieldcontain"</code> attribute to group them.</p>
<pre><code>
&lt;div data-role=&quot;fieldcontain&quot;&gt;
&lt;label for=&quot;slider2&quot;&gt;Select slider:&lt;/label&gt;
&lt;select name=&quot;slider2&quot; id=&quot;slider2&quot; data-role=&quot;slider&quot;&gt;
&lt;option value=&quot;off&quot;&gt;Off&lt;/option&gt;
&lt;option value=&quot;on&quot;&gt;On&lt;/option&gt;
&lt;/select&gt;
&lt;/div&gt;
</code></pre>
<p>A radiobutton list is displayed like this:</p>
<fieldset data-role="controlgroup" data-role="fieldcontain">
<legend>Choose one:</legend>
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked" />
<label for="radio-choice-1">Choice 1</label>
<input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2" />
<label for="radio-choice-2">Choice 2</label>
<input type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3" />
<label for="radio-choice-3">Choice 3</label>
<input type="radio" name="radio-choice-1" id="radio-choice-4" value="choice-4" />
<label for="radio-choice-4">Choice 4</label>
</fieldset>
<fieldset data-role="controlgroup" data-type="horizontal" data-role="fieldcontain">
<legend>Same with theme change:</legend>
<input type="radio" name="radio-choice-b" id="radio-choice-c" value="on" checked="checked" />
<label for="radio-choice-c">On</label>
<input type="radio" name="radio-choice-b" id="radio-choice-d" value="off" />
<label for="radio-choice-d">Off</label>
<input type="radio" name="radio-choice-b" id="radio-choice-e" value="other" />
<label for="radio-choice-e">Other</label>
</fieldset>
</form>
</div><!-- /content -->
</div><!-- /page -->
</body>
</html>