简体   繁体   English

WordPress的onClick功能在li标签中不起作用,发布了链接

[英]Wordpress onClick function not working in li tag, posted link

I am updating a wordpress website and for some reason, this onClick function is no longer working. 我正在更新wordpress网站,由于某种原因,此onClick功能不再起作用。 Here it is in the html: 它在html中:

    <div class="monthes">
        <!--<div class="location_title">Great Wall Hiking Locations</div>-->
        <div class="month_list">
            <ul class="month">
            <?php for($i=1; $i<=12; $i++){
                if($i!=$cur_month)
                   echo "<li onclick=\"tabTurn(this, 'on', 'month_desc');\" class=\"off\">$month[$i]</li>";
                else
                   echo "<li onclick=\"tabTurn(this, 'on', 'month_desc');\" class=\"on\">$month[$i]</li>";
            }?>
            </ul>
        </div>
    </div>

And here is the function: 这是函数:

function tabTurn(presObj, classon, showdiv){
    var pObj = presObj.parentNode;
    var items =pObj.getElementsByTagName('li');

    for(var i=0; i<items.length; i++){
        var n = i + 1;
        var cntDiv = $('location_desc_' + n);
        //alert(cntDiv);
        if(items[i] == presObj){
            items[i].className=classon;
            cntDiv.className = showdiv;
        }
        else{
            items[i].className='off';
            cntDiv.className = 'undis';
        }
    }
}

Does anyone know why this would stop working? 有谁知道为什么这将停止工作? Is there a way I can get rid of this inline onClick and just do it with javascript and not php? 有没有一种方法可以摆脱此内联onClick,而只使用javascript而不是php? The issue can be found at this link here: http://staging.chinahiking.cn/agenda/ 可以在以下链接找到此问题: http : //staging.chinahiking.cn/agenda/

As you can see, the onclick is actually working and turning the months on/off, but the tabBurn function isn't working 如您所见,onclick实际上正在工作,可以打开/关闭月份,但是tabBurn函数不起作用

You can use a passive event listener: 您可以使用被动事件监听器:

$(document).on("click", "class-name", function(){tabTurn(this, 'on', 'month_desc');});

where as "class-name" you need to add a class name to your <li> element (or an id) 作为“类名”,您需要在<li>元素(或ID)中添加类名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM