开发者

Jquery onclick change value

I have some jquery tabs on my page the code for them is:

//tabs options
$("#tabs").tabs({ collapsible: true,  selected: -1 });  

I want to create a button that will toggle the above option 'selected: -1'

I need it to change the value of 'selected' to '0' then back to '-1'

How would I do this?

<a href="#">Toggle V开发者_如何学运维iew</a>


You can do it like this:

<a href="#" id="toggle">Toggle View</a>

Then use the .toggle() function, like this:

$("#toggle").toggle(function() {
  $("#tabs").tabs("option", "selected", -1);
}, function() {
  $("#tabs").tabs("option", "selected", 0);  
});

When you use .toggle(), it'll cycle through the functions you pass in on each click, so on the first click the first function runs, next click the next, etc...if you pass only 2 functions, you're toggling between them on each click.


Nick is right.

You can use the .toggle() to switch between the values.

Since you need a button to toggle the value you may add this too along with Nick's code.

<button>Switch</button>

$("button").click(function () { $("#toggle").toggle(...)});

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜