2013-07-09 58 views
0

我已經看到了這個問題的變化,但不是我在SO上的具體情況,所以在這裏。爲jQuery Mobile fieldset控制組動態添加無線電輸入

我在使用jQuery Mobile向現有控件組中動態添加新的無線電輸入時遇到了問題。它會添加,但樣式不正確,並且它看起來不正確地與其他輸入交互。

這裏是我的小提琴: http://jsfiddle.net/cjindustries/3mQF6/

任何人都可以看到我在做什麼錯?或者是再次重新生成整個fieldset/controlgroup的情況? :(

感謝!下面太代碼...

 <div id="testPage" data-role="page"> 
     <div data-role="content"> 
    <fieldset data-role="controlgroup"> 
     <legend>Radio buttons, vertical controlgroup:</legend> 
      <input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked"> 
      <label for="radio-choice-1">Cat</label> 
      <input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2"> 
      <label for="radio-choice-2">Dog</label> 
      <input type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3"> 
      <label for="radio-choice-3">Hamster</label> 
      <input type="radio" name="radio-choice-1" id="radio-choice-4" value="choice-4"> 
      <label for="radio-choice-4">Lizard</label> 
    </fieldset> 
     </div> 
    </div> 

$('<input type="radio" name="radio-choice-5" id="radio-choice-5"><label for="radio-choice-5">Horse</label>') 
    .appendTo("fieldset"); 

$("fieldset").trigger('create'); 

回答

1

您需要使用name="radio-choice-1"因爲你已經在上面使用,解決了您的行爲問題

行爲問題,以下變化 解決您的動態添加收音機的修改代碼

$('<input type="radio" name="radio-choice-1" id="radio-choice-5"><label for="radio-choice-5">Horse</label>').appendTo("fieldset"); 

樣式問題用以下更改解決 Jus牛逼重新代替字段集

$("div").trigger('create'); 

檢查Fiddle Demo

+1

衛生署格!我非常忙於尋找一個我忽略了基本HTML的jQM問題!謝謝:) – Chris

+0

謝謝,工作正常。 – 2014-03-14 02:05:37