开发者

Help with JS return statement

this is probably an easy one, but I am new to JavaScript.

When I click on a tab which has a special id, I want that id saved in a variable. So far, so good. But if I click on a other button I want that button to work with that previous id oft he tab.开发者_如何学编程 How am I using the return statement correctly?

Thanks!


// 0 = no tab 
var myTabID = 0

function doNewTab(newTabID)
{
   // If the tab has not been set
   if(myTabID <> 0){
        // Do whatever you want with the tab ID in here
        alert(myTabID);
   }

   // Set new tab ID
   myTabID = newTabID;
}

Then in your HTML:

<a onclick="doNewTab(1)" href="#">Tab1</a><br />
<a onclick="doNewTab(2)" href="#">Tab2</a><br />
<a onclick="doNewTab(3)" href="#">Tab3</a><br />


var tabId = 0

function buttonClick(obj) {
  tabId = obj.id
}

<button onclick="buttonClick(this)">Button</button>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜