我有一个列表项:
<li id="optionCarousel" onclick="toggleTick(this)"><a><img class="tick" id="optionCarousel_Tick" src="/images/tick.png">Carousel</a></li>
当我打电话给我的方法时:
function toggleTick(element) {
var elementText = element.id += "_Tick";
var tickElement = $g(elementText);
if (tickElement != null) {
if (tickElement.style.visibility == "visible") {
tickElement.style.visibility = "hidden";
}
else {
tickElement.style.visibility = "hidden";
}
}
}
它隐藏了整个列表项,而不仅仅是我传递的图像。关于如何隐藏图像的任何想法?
小提琴HERE
答案 0 :(得分:0)
尝试
function toggleTick(element) {
var elementText = element.id += "_Tick";
var tickElement = $g(elementText);
tickElement.toggle()
}
答案 1 :(得分:0)
做这样的事情:
function toggleTick(element) {
var elementText = element.id += "_Tick";
var tickElement = document.getElementById(elementText );
if (tickElement != null) {
if (tickElement.style.visibility == "visible") {
tickElement.style.visibility = "hidden";
}
else {
tickElement.style.visibility = "hidden";
}
}
}
答案 2 :(得分:0)
试试这个,这将有助于你
$('#optionCarousel').click(function () {
var tickElement = '#' +$(this).prop('id')+'_Tick';
$(tickElement).slideToggle();
});
小提琴Here