尝试根据所选的单选按钮显示一个形状



我使用拉斐尔.js来绘制形状取决于选择哪个单选按钮,但我只希望一次显示一个形状。当我点击单选按钮时,我一次得到了所有的形状当我点击另一个单选按钮时,这些形状会被重新绘制。非常感谢您的帮助。

HTML :

    <input name="shapes" id="square" type="radio">
    <label for="square">Square</label>
    <input name="shapes" id="rectangle" type="radio">
    <label for="rectangle">Rectangle</label>
    <input name="shapes" id="circle" type="radio">
    <label for="circle">Circle</label>

拉斐尔/jquery

    $(':radio[name="shapes"]').on('click', function(){
       var shapeName = $(this).attr('id');
       var square = p.rect(10,10,40,40);
       var rectangle = p.rect(20,20,50,80);
       var circle = p.circle(40,40,10);
       console.log(shapeName);
       return shapeName;
    });
$(':radio[name="shapes"]').on('click', function(){
   var shapeName = $(this).attr('id');
   if(shapeName == "square")
       p.rect(10,10,40,40);
   else if(shapeName == "rectangle")
       p.rect(20,20,50,80);
   else if(shapeName == "circle")
       p.circle(40,40,10);
   console.log(shapeName);
   return shapeName;
});

最新更新