创建一个通用扰流盒(Creating a universal spoiler box)
$(document).ready(function(){ $("#spoil").click(function(){ $(this).toggle(); }); });
我正在使用Jquery来创建一个扰流板或下拉框,所以你点击按钮,然后信息消失,然后当你再次点击它时,它会回来。 我正在计划有很多这样的产品,并且想知道如何改变我的代码,这样它就可以与所有不需要每次更改js的扰流盒一起工作。 谢谢
我只是在切换框的内容而不是它自己的按钮之后。
$(document).ready(function(){ $("#spoil").click(function(){ $(this).toggle(); }); });
I am using Jquery to create a spoiler or drop down box so you click the button then the information disappears then when you click it again it comes back. I am planing on having many of these and was wondering how to transform my code so it would work with all the spoiler boxes with out needing to alter the js each time. Thank you
I am only after the content of the box being toggled not the button it self.
满意答案
你的意思是
$(function() { $(".toggle").on("click",function() { $(".toggled").toggle().removeClass("toggled"); $(this).next(".spoiler").toggle().addClass("toggled"); }) });
使用链接我会添加preventDefault:
$(function() { $(".toggle").on("click",function(e) { e.preventDefault(); // do not follow the link $(".toggled").toggle().removeClass("toggled"); $(this).next(".spoiler").toggle().addClass("toggled"); }) });
Do you mean
$(function() { $(".toggle").on("click",function() { $(".toggled").toggle().removeClass("toggled"); $(this).next(".spoiler").toggle().addClass("toggled"); }) });
Using a link I would add preventDefault:
$(function() { $(".toggle").on("click",function(e) { e.preventDefault(); // do not follow the link $(".toggled").toggle().removeClass("toggled"); $(this).next(".spoiler").toggle().addClass("toggled"); }) });
相关问答
更多标签中带有BBCodes的BBCode扰流板(BBCode spoiler with BBCodes in the label)
在桌行的掠夺者与css选择器(Spoiler on table row with css selector)
如何在github wiki页面中制作“spoiler”文本?(How to make “spoiler” text in github wiki pages?)
如何使用jQuery Spoiler(How to use a jQuery Spoiler)
创建一个通用扰流盒(Creating a universal spoiler box)
处理破坏者BBcode Android(Handling spoiler BBcode Android)
什么是“通用应用”?(What is a “universal app”?)
扰流板中的代码块与降价(Code block in spoiler with markdown)
相关文章
更多A Great List of Windows Tools
She’s Not Carrying A Handbag
ServletOutputStream cannot be resolved to a type
Book Report: THE SOUL OF A NEW MACHINE
每日英语:Man Without a Country
[译文] 恶意软件行为综述 - A View on Current Malware Behaviors
Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
[转]So You Want To Be A Producer
Becoming a data scientist
trouble is a friend
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!