-1

このコードは、ID に応じて要素の表示と非表示を切り替えることができるようにすることを目的としています。

標準のJavaScript関数のように変数を簡単に指定できるようにコードを変換しようとしています。

このように、関数を呼び出して ID を属性として与えるだけで、html 要素を非表示または表示したいときに、常にこの関数を使用できます。

このバージョンのコードを試していますが、うまくいきません。しかし、変更したい要素の ID を指定しているので、間違いがあります。

var x;
x=$(document);
x.ready(init);

function init(){
            var x;
            x=$("#titulo1");  // Here is the ID of the control element
            x.click(Qocult_most("#subtitulo1"));
            }

function Qocult_most(id){  //Show and scrolls down till the page's end
            var x;
            x=$(id); //Here is the ID element to show
            x.toggle(50);
            $("html, body").animate({ scrollTop: $("#STH").offset().top }, 1000);
                    }

そして、この JQuery を呼び出す HTML 本文は次のとおりです。

 <body>

 <div id="titulo1" class="contenedor"> I'm title 1  
 <div id="subtitulo1">  Text to show as a sub-menu when title 1 is clicked</div>
 <div id="titulo2" class="contenido"> I'm title 2 

</div>

</div>


</body>
4

1 に答える 1