我使用 jQuery 和 Raphael 根据选中的复选框隐藏/显示形状,但我收到一个 .show();/.hide(); 的萤火虫错误 当我将变量分配给复选框 id 并尝试显示/隐藏时,它们不是函数。但是当我直接传递形状变量名称并显示/隐藏它时它可以工作。
非常感谢关于为什么第一种方法返回错误或指向我的教程的任何帮助。谢谢!
jQuery:
var p = Raphael("test");
var square = p.rect(100, 100, 60, 60);
square.attr('fill', 'orange');
square.hide();
var circle = p.circle(250, 250, 60);
circle.attr('fill', 'yellow');
circle.show();
$("#shapePosition input[type=checkbox]").on('click', function () {
var $this = $(this);
var shapeId = $(this).attr('id');
if ($this.is(':checked')) {
alert(shapeId);
square.show(); //This works
shapeId.show(); //This does not work(Error type: is not a function)
} else {
shapeId.hide();
}
});
小提琴: