如果选中单选按钮,则显示THREE.Group()?

时间:2015-08-27 12:15:48

标签: javascript jquery three.js

我想要做的是在选中某个单选按钮时显示一个组。 我怎样才能做到这一点?

 <input id="option1" type="radio" name="options" value="" checked="checked"/>
 <input id="option2" type="radio" name="options" value="" />   

加载&#34; groupA&#34;如果是单选按钮&#34; option1&#34;已选中

var groupA = new THREE.Group();

  // Basis
   loader.load('/models/model1.js', function(geometry){
       var mesh = new THREE.Mesh(geometry, material);
       loadJson(mesh);
   });
    function loadJson(mesh){
        groupA.add(mesh);
    }


  // Basis
   loader.load('/models/model2.js', function(geometry){
       var mesh = new THREE.Mesh(geometry, material);
       loadJson(mesh);
   });
    function loadJson(mesh){
        groupA.add(mesh);
    }

scene.add( groupA );

加载&#34; groupB&#34;如果是单选按钮&#34; option2&#34;已选中

var groupB = new THREE.Group();

  // Basis
   loader.load('/models/model1.js', function(geometry){
       var mesh = new THREE.Mesh(geometry, material);
       loadJson(mesh);
   });
    function loadJson(mesh){
        group.add(mesh);
    }


  // Basis
   loader.load('/models/model2.js', function(geometry){
       var mesh = new THREE.Mesh(geometry, material);
       loadJson(mesh);
   });
    function loadJson(mesh){
        groupB.add(mesh);
    }

scene.add( groupB );

非常感谢你!

1 个答案:

答案 0 :(得分:0)

试试这个:将值作为option1和option2放到相应的单选按钮上,并在点击处理程序中检查值以加载相应的组。

HTML:

<input id="option1" type="radio" name="options" value="option1" checked="checked"/>
<input id="option2" type="radio" name="options" value="option2" />

jQuery的:

$(function(){
    //load group for already selected radio button
    var checkedRadioVal = $('input[name="options"]:checked').val();
    if(checkedRadioVal == "option1")
    {
        //call code to load group A
    }
    else  if(checkedRadioVal == "option2")
    {
       //call code to load group B
    }

    //click handler for radio button
    $('input[name="options"]').click(function(){
        var value = $(this).val();
        if(value == "option1")
        {
          //call code to load group A
        }
        else  if(value == "option2")
        {
          //call code to load group B
        }
    });
 });