0

我一直坚持一个代码几天,和我真正想要做的是追加单选按钮下一个和以前(链接/按钮)。追加下一个和以前以单选按钮

<div id="slides"> 
     <ul class="options-list"> 
      <li> 
      <input type="radio" class="getradiotomove" id="bundle-73" name="bundle_option" value="73"> 
      <input type="radio" class="getradiotomove" id="bundle-72" name="bundle_option" value="72"> 
      <input type="radio" class="getradiotomove" id="bundle-74" name="bundle_option" value="74"> 
     </ul> 
    </div> 

    <div id="buttons"> 
     <a href="#" id="prev">prev</a> 
     <a href="#" id="next">next</a> 
     <div class="clear"></div> 
    </div> 

什么,我想在这里做的是,当我点击下一步,它将选择它下面的单选按钮,所以上面的代码有束-73,捆绑-72和捆绑-74,说如果选择的默认值是bundle-73,那么当我点击下一步时,它应该选择bundle-72。

回答

1

你的HTML看起来坏,所以我会假设你真的是这样的:

<div id="slides"> 
    <ul class="options-list"> 
     <li><input type="radio" class="getradiotomove" id="bundle-73" name="bundle_option" value="73"></li> 
     <li><input type="radio" class="getradiotomove" id="bundle-72" name="bundle_option" value="72"></li> 
     <li><input type="radio" class="getradiotomove" id="bundle-74" name="bundle_option" value="74"></li> 
    </ul> 
</div> 

然后你下一个行动应该是这样的:

$('#next').click(function() { 
    var $all  = $('.getradiotomove');   // Get them all 
    var $current = $('.getradiotomove:checked'); // Get the current one 

    var index = $all.index($current) + 1;   // Find the index of the next one 
    if(index >= $all.length)      // Wrap around at the end 
     index = 0; 
    $($all[index]).attr('checked', 'checked'); // Check it. 
}); 

演示:http://jsfiddle.net/ambiguous/hTgv3/1/

这假设你只有一组单选按钮。

你应该能够理清自己以前行动。

参考文献:

+0

如果有一个人我真的很感谢,是你,你真的救了我的命! omg,我不能够感谢你!非常感谢你! – Xavien

0

也许somethining这样吗?

<ul class="options-list"> 
    <li> 
     <input type="radio" name="bundle_option" value="73"> 
    </li> 
    <li> 
     <input type="radio" name="bundle_option" value="72"> 
    </li> 
    <li> 
     <input type="radio" name="bundle_option" value="74"> 
    </li> 
</ul> 

和javascript:

$('#next').click(function(){ 
    $('[name=bundle_option]:checked').parent().next().children('[name=bundle_option]').attr('checked', true); 
    return false; 
}); 
0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html lang="es"> 
    <head> 
    <title>Ejemplo</title> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
     <script type="text/javascript"> 
      $(document).ready(function() { 
       $('#next').click(function() { 
         var checkedOp = $('input[name=bundle_option]:checked') 
         var match = checkedOp.next('input[name=bundle_option]'); 
         if (match.length > 0) 
          checkedOp.removeAttr('checked').next('input[name=bundle_option]').attr('checked', 'checked'); 
        }); 
       $('#prev').click(function() { 
         var checkedOp = $('input[name=bundle_option]:checked'); 
         var match = checkedOp.prev('input[name=bundle_option]'); 
         if (match.length > 0) 
          checkedOp.removeAttr('checked').prev('input[name=bundle_option]').attr('checked', 'checked'); 
       }); 
       }     
      ); 

     </script> 
    </head> 
    <body> 
    <div id="slides"> 
      <input type="radio" class="getradiotomove" id="bundle-73" name="bundle_option" value="73" checked="checked"> 
      <input type="radio" class="getradiotomove" id="bundle-72" name="bundle_option" value="72"> 
      <input type="radio" class="getradiotomove" id="bundle-74" name="bundle_option" value="74"> 
    </div> 
    <div id="buttons"> 
     <a href="#" id="prev">prev</a> 
     <a href="#" id="next">next</a> 
     <div class="clear"></div> 
    </div> 
    </body> 
</html> 
相关问题