0

我正在使用 raphael.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;

    });
4

1 回答 1

1
$(':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;

});
于 2013-04-04T18:04:09.577 回答