我使用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;
});
答案 0 :(得分: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;
});