1

我有一个列表项:

<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

4

3 回答 3

0

试试这个,这对你有帮助

$('#optionCarousel').click(function () {
    var tickElement = '#' +$(this).prop('id')+'_Tick';
    $(tickElement).slideToggle();
});

小提琴Here

于 2013-09-17T17:33:45.050 回答
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";
        } 
    }
}
于 2013-09-17T16:15:39.693 回答
0

尝试

function toggleTick(element) {
    var elementText = element.id += "_Tick";
    var tickElement = $g(elementText);
    tickElement.toggle()
}
于 2013-09-17T16:08:46.357 回答