2014-03-05 19 views
1

我使用jQuery UI已經形式, 我必須做一個選擇電臺至極需要從DB值,所以我嘗試這樣做的:jQuery UI的創造了很多不良跨度

//function wich reutrn applicable ratio for the pricing 
function getAvailableCoeff(){ 


echo "<td>Coeff : </td>"; 
    echo "<td><div class='radio'>"; 
    $req = "SELECT coef,id_type FROM type_client WHERE valide =1 GROUP BY coef"; 
    $res = mysql_query($req); 

    while($row=mysql_fetch_array($res)){ 
     $id = 'coeff'.$row['id_type']; 
     $value = $row['coef']; 
     $input = "<label for='$id'>$value</label>"; 
     $input .= "<input type='radio'id='$id' name='coeff' value='$value'/>"; 
     echo $input; 
    } 
    echo "</div></td>"; 
} 

沒有什麼很困難沒有?但是當我把它發送到集成服務器時,我看到了巨大的單選按鈕(它們是3個atm)! i let you check it here (屏幕上的 「1」, 「2」, 「3」, 「4」, 「QUADRI」 上, 「5」, 「6」 收音機按鈕被硬編碼與此語法:<input type="radio" id="spT_radio-coul-1" value="1" name="nbCoul" /> <label for="spT_radio-coul-1">1</label>

此外,該無線電buttondon't通形式sumbission,$_POST['coef']仍是空的.. 所以,我看看到HTML和.. WTF 每個單選按鈕,得到這樣的代碼:

<label for="coeff5" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"> 
<span class="ui-button-text"> 
<span class="ui-button-text"> 
<span class="ui-button-text"> 
<span class="ui-button-text"> 
<span class="ui-button-text"> 
<span class="ui-button-text">0.66</span></span></span></span></span></span></label> 

所以jQuery的汽車生成所有這些跨度,但如何刪除它們,以獲得法線單選按鈕? 有沒有人遇到過這種問題與jq uery ui?

臨時(醜)解決方案:

.ui-button-text-only .ui-button-text { 
padding:2px; 
!important; 

}

最終解決方案(THX非標):

//function wich reutrn applicable ratio for the pricing 
function getAvailableCoeff($form){ 
    echo "<td>Coeff : </td>"; 
    echo "<td><div class='radio'>"; 
    $req = "SELECT coef,id_type FROM type_client WHERE valide =1 GROUP BY coef"; 
    $res = mysql_query($req); 
    while($row=mysql_fetch_array($res)){ 
     $id = $form.'coeff'.$row['id_type'].$i; 
     $value = $row['coef']; 
     $input = "<label for='$id'>$value</label>"; 
     $input .= "<input type='radio' id='$id' name='coeff' value='$value'/>"; 
     echo $input; 
     $i++; 
    } 
    echo "</div></td>"; 
} 

我傳遞一個字符串值,爲每個調用,這樣的ID是真的很獨特!

+0

指向顯示問題的真實頁面的鏈接將非常有用。 –

+0

在那個鏈接中,我沒有看到任何'coeff'輸入?他們在哪? –

+0

我的壞,通過禁用登錄要求我無意中禁用db訪問.. 這很好現在 –

回答

1

解決!問題是使用重複的id s。

在頁面上,所有的<input>使用同一臺id S(#coeff5#coeff2#coeff1)。 jQuery UI使用那些id s來添加跨度,所以重複項將破壞它。

id s必須是唯一的。

我做了一些測試案例是:

不工作:http://jsfiddle.net/PGcL4

Working JSFiddle

所以,你會改變你的PHP代碼:

//function wich reutrn applicable ratio for the pricing 
function getAvailableCoeff(){ 
    echo "<td>Coeff : </td>"; 
    echo "<td><div class='radio'>"; 
    $req = "SELECT coef,id_type FROM type_client WHERE valide =1 GROUP BY coef"; 
    $res = mysql_query($req); 

    $i=0; 
    while($row=mysql_fetch_array($res)){ 
     $id = 'coeff'.$row['id_type'].$i; 
     $value = $row['coef']; 
     $input = "<label for='$id'>$value</label>"; 
     $input .= "<input type='radio' id='$id' name='coeff' value='$value'/>"; 
     echo $input; 
     $i++; 
    } 
    echo "</div></td>"; 
} 

,像要求,使所有的id獨特的。

+0

我更新了php函數,但跨度仍然在這裏。 –