JQuery单选按钮组处于活动状态和非活动状态

时间:2012-03-10 17:43:18

标签: jquery user-interface button

好的,所以我尝试使用按钮设置。

如此公平,我已经能够将它们转换为链接。 但是,问题是单选按钮不能保持其活动状态。

以下是jquery的代码:

$( "#radio" ).buttonset();

$("input:radio[name=radio]").click(function() {
var id = $("input[@name=radio]:checked").attr('id');
window.location.replace("player.php?id=<?php echo $id; ?>&action="+id);
}

以下是我的网页背后的butonset + PHP代码的代码:

<form>
 <div id="radio" class="ui-buttonset">
 <input type="radio" id="season" name="radio" value="season" /><label                  for="season">Season</label>
 <input type="radio" id="playoff" name="radio" value="playoff" /><label for="playoff">Playoffs</label>
 <input type="radio" id="carrer" name="radio" value="carrer" /><label for="carrer">Carrer</label>
 <input type="radio" id="carrer_playoff" name="radio" id="carrer_playoff"/><label for="carrer_playoff">Carrer playoffs</label>
 </div>
</form>
</center>

<br/><br/>

<?php
 if($action == "playoff"){
 include("player_playoff.php");
 }
 else if($action == "carrer"){
 include("player_carrer.php");
 }
 else if($action == "carrer_playoff"){
 include("player_carrer_playoff.php");
 }
 else{
 include("player_season.php");
 }

?>

这是网页: http://uweave.ca/uw-perso/Aravinthan_Sivaneswaran/COD_Circuit-TW/public%20v2.0/player.php?id=1&action=season

感谢您的帮助, ARA

编辑:         if($ radio.is(':checked')=== false){             $ radio.filter('[value =]')。attr('checked',true);         }         if($ radio.filter('[value =]')。attr('checked',true)){             警报( “IN”);         }

我这样做是为了检查,但它总是用IN警告我,但它没有把它置于检查(活动)状态......

1 个答案:

答案 0 :(得分:0)

在阅读了您的问题的评论后,这就是您要找的内容

$(function(){
    $('input:radio[id="<?php echo $action; ?>"]').attr('checked','checked');
});

http://jsfiddle.net/seLTY/