Jquery onclick改变值
我的页面上有一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做:
然后使用
.toggle()
函数,像这样:当您使用
.toggle()
时,它将循环遍历您在每次单击时传入的函数,因此第一次单击时,第一个函数运行,接下来单击下一个函数,依此类推...如果您仅传递 2 个函数,则每次单击时都会在它们之间切换。You can do it like this:
Then use the
.toggle()
function, like this: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.尼克是对的。
您可以使用
.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(...)});