Jquery onclick改变值

发布于 2024-09-03 15:46:39 字数 293 浏览 1 评论 0原文

我的页面上有一些 jquery 选项卡,它们的代码是:

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

我想创建一个按钮来切换上述选项“selected: -1”

我需要它将“selected”的值更改为“0”,然后返回到'-1'

我该怎么做?

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

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 View</a>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箹锭⒈辈孓 2024-09-10 15:46:39

你可以这样做:

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

然后使用 .toggle() 函数,像这样:

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

当您使用 .toggle() 时,它将循环遍历您在每次单击时传入的函数,因此第一次单击时,第一个函数运行,接下来单击下一个函数,依此类推...如果您仅传递 2 个函数,则每次单击时都会在它们之间切换。

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.

断爱 2024-09-10 15:46:39

尼克是对的。

您可以使用 .toggle() 在值之间切换。

由于您需要一个按钮来切换值,因此您也可以将其与 Nick 的代码一起添加。

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

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(...)});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文