1

There's something wrong with my code and I can't figure out what it is. I am using jQuery mobile to generate radio buttons forms. However, it is not working as expected. It appears just like this (picture link: http://tinypic.com/r/4q0os8/5 ) while it should list all the radio buttons below each other

Generated HTML:

 <div data-role="content">
                <h3>
                    Answer This Question
                </h3>
                <form action="storeresponse.php" method="GET" ajax-data="false">
                    <div data-role="fieldcontain">
                        <fieldset data-role="controlgroup" data-type="vertical">
                            <legend>
                                What is your favorite food?                            </legend>

                                <input id="radio1" value="" name="option" data-theme="c" type="radio">
                                <label for="radio1">Pizza</label>

                                <input id="radio1" value="" name="option" data-theme="c" type="radio">
                                <label for="radio1">Pasta</label>

                                <input id="radio1" value="" name="option" data-theme="c" type="radio">
                                <label for="radio1">Chicken wings</label>

                                <input id="radio1" value="" name="option" data-theme="c" type="radio">
                                <label for="radio1">Noodles</label>
                                                        </fieldset>
                        <input type="submit" data-theme="b" data-icon="check" data-iconpos="right"
                               value="Submit">
                    </div>

                </form>

It's generating the same ID for each radio button while I've added $i++

4

2 回答 2

3

附加提示: $i应该放在外面while loop


在您的情况下,您需要增强标记contorlgroupradio buttons使用create方法。

jQuery Mobile 提供了一种易于增强的动态插入元素,并通过这种方式使它们看起来像静态元素。

演示

用于创建和增强复选框/单选按钮:

$('[type=radio]').checkboxradio().trigger('create');

加强controlgroup

$('[data-role=controlgroup]').controlgroup().trigger('create');
于 2013-05-25T21:08:52.427 回答
0

用标签包裹<input...>和标签:<label><p>

<?php
                        $sql = "SELECT option_description FROM options WHERE question_id = '$qid'";
                        $result = mysql_query($sql) or die(mysql_error());
                        while ($row = mysql_fetch_row($result)) {
                            $i = 1;
                            $optionName = $row['0'];
                            ?> 
                            <p>
                                <input id="<?php echo 'radio' . $i ?>" value="<?php echo $optionName ?>" name="option" data-theme="c" type="radio">
                                <label for="<?php echo 'radio' . $i ?>"><?php echo $optionName; ?></label>
                            </p>
                            <?php $i++;
                        } ?>
于 2013-05-25T20:26:53.840 回答