2016-12-10 10 views
-2

私はプログラムでタブをクリックするスクリプトを書こうとしています。このタブでは、ウェブサイト上のdivをもっと明らかにし、それらの公開されたdivでいくつかのアクションを実行します。ボタンをプログラムでクリックすると、何かが実行されますか?

は今のところ、私は

document.getElementById("buttonid").click(); // which reveals another section of the webpage console.log($("#idofnewdiv"));

を持っている...しかし、新しいのdivを見ていないようです。しかし、私が手動でボタンをクリックすると、console.logは適切にそれを印刷することができます。私は何か間違っているのですか?

+0

クリックには何の処置もなく、jQueryを使用している場合は、それらの機能を最大限に活用してください。 :) –

+0

http://stackoverflow.com/questions/2705583/how-to-simulate-a-click-with-javascript –

+0

続きを読む書籍 –

答えて

0
var button = document.getElementById("buttonid"); 

button.addEventListener("click", function(){ 
    alert("Button is Clicked"); 
}); 

button.click(); 
0

もあなたはこのようにそれを使用することができます:

var mButton = document.getElementById("buttonId"); 

mButton.onClick(function(){ 

    your code to execute here. 

}); 
0

それはあなたのclick機能が何かをやっているようには見えません。次のコードは、<div>のすべてが既に隠されていることを前提としています。

var listOfDivsToReveal = document.getElementsByClassName("divsToReveal"); 
var listOfDivsIter = 0; 
$("#thebuttonID").click(function(){ 
    if(listOfDivsIter > listOfDivsToReveal.length){ 
     //do whatever you do when all of your <div> tags are revealed 
    } 
    listOfDivsToReveal[listOfDivsIter++].style.display = "inline";//Or your desired display. 
}); 
関連する問題