简体   繁体   English

Javascript控制台jquery slideDown函数

[英]Javascript Console jquery slideDown function

Javscript code Javscript代码

/* ---------- Submenu ---------- */ / * ----------子菜单---------- * /

$('.dropmenu').click(function(e){

    e.preventDefault();

    $(this).parent().find('ul').slideDown();

});

webpage code 网页代码

    <li>
        <a class="dropmenu" href=""><i class="fa-icon-folder-close-alt"></i><span class="hidden-tablet"> Databases</span></a>
        <ul>
            <li><a class="submenu" href="/rinks"><i class="fa-icon-file-alt"></i><span class="hidden-tablet"> Rinks</span></a></li>
            <li><a class="submenu" href=""><i class="fa-icon-file-alt"></i><span class="hidden-tablet"> Users</span></a></li>
        </ul>   
    </li>

So I have this piece of code that triggers a dropdown menu to expand when the element "a class="dropmenu" href=" is clicked. 因此,当单击“a class =”dropmenu“href =”元素时,我有这段代码触发下拉菜单展开。

I am trying to trigger this event when another element has a value set to it but I can't figure out how to call the slidedown function from the console. 我试图在另一个元素设置了一个值时触发此事件,但我无法弄清楚如何从控制台调用slidedown函数。

I dont want to trigger with the click() command. 我不想用click()命令触发。 I want to be able to execute $(this).parent().find('ul').slideDown(); 我希望能够执行$(this).parent()。find('ul')。slideDown(); but from the console side. 但是从控制台方面来说。 That way I can call other functions like slideToggle. 这样我就可以调用其他函数,比如slideToggle。 Basically I want to be able to rung the below code to trigger the slidedown, not the click event, I would remove the click event. 基本上我希望能够敲响下面的代码来触发slidedown,而不是click事件,我会删除click事件。

    $(document).ready(function(){
   //Message functions
    if (document.getElementbyId("testing").value == "BestGame"){
        $(this).parent().find('ul').slideDown();

    }

You can declare a method to be called in the click event 您可以声明要在click事件中调用的方法

 $('.dropmenu').click(function (e) {
     var el = this;
     e.preventDefault();
     toggleMenu(el);
 };
 var toggleMenu = function (el) {
     $(el).parent().find('ul').slideDown();
 }

So from the console all you would have to do is 因此,从控制台,你所要做的就是

 toggleMenu('.dropmenu')

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

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