Jquery 如何使显示和隐藏切换特定
我使用Jquery创建了一个简单的“显示和隐藏”切换,但我希望它特定于每个div,因为我将重用该类 我知道我必须使用(这个)功能,但似乎无法正确放置它 非常感谢你的帮助Jquery 如何使显示和隐藏切换特定,jquery,toggle,show-hide,Jquery,Toggle,Show Hide,我使用Jquery创建了一个简单的“显示和隐藏”切换,但我希望它特定于每个div,因为我将重用该类 我知道我必须使用(这个)功能,但似乎无法正确放置它 非常感谢你的帮助 $(document).ready(function() { $('.showmenu').click(function() { $('.menu').toggle("toogle"); }); }); 我建议: $(document).ready(function () {
$(document).ready(function() {
$('.showmenu').click(function() {
$('.menu').toggle("toogle");
});
});
我建议:
$(document).ready(function () {
// attaching the click-event handler to the class:
$('.showmenu').click(function () {
// this is the DOM node of the clicked-element,
// $(this) is the jQuery object formed from the clicked DOM node
$(this)
// traverses to the next sibling of the clicked element,
// if it's a 'div' with the 'menu' class-name:
.next('div.menu')
// toggles that element:
.toggle("toogle");
});
});
$(文档).ready(函数(){
$('.showmenu')。单击(函数(){
$(this.next('div.menu')。切换(“toogle”);
});
});代码>
点击这里
- 按钮1
- 按钮2
- 按钮3
点击这里
- 按钮1
- 按钮2
- 按钮3
我建议:
$(document).ready(function () {
// attaching the click-event handler to the class:
$('.showmenu').click(function () {
// this is the DOM node of the clicked-element,
// $(this) is the jQuery object formed from the clicked DOM node
$(this)
// traverses to the next sibling of the clicked element,
// if it's a 'div' with the 'menu' class-name:
.next('div.menu')
// toggles that element:
.toggle("toogle");
});
});
$(文档).ready(函数(){
$('.showmenu')。单击(函数(){
$(this.next('div.menu')。切换(“toogle”);
});
});代码>
点击这里
- 按钮1
- 按钮2
- 按钮3
点击这里
- 按钮1
- 按钮2
- 按钮3
我建议:
$(document).ready(function () {
// attaching the click-event handler to the class:
$('.showmenu').click(function () {
// this is the DOM node of the clicked-element,
// $(this) is the jQuery object formed from the clicked DOM node
$(this)
// traverses to the next sibling of the clicked element,
// if it's a 'div' with the 'menu' class-name:
.next('div.menu')
// toggles that element:
.toggle("toogle");
});
});
$(文档).ready(函数(){
$('.showmenu')。单击(函数(){
$(this.next('div.menu')。切换(“toogle”);
});
});代码>
点击这里
- 按钮1
- 按钮2
- 按钮3
点击这里
- 按钮1
- 按钮2
- 按钮3
我建议:
$(document).ready(function () {
// attaching the click-event handler to the class:
$('.showmenu').click(function () {
// this is the DOM node of the clicked-element,
// $(this) is the jQuery object formed from the clicked DOM node
$(this)
// traverses to the next sibling of the clicked element,
// if it's a 'div' with the 'menu' class-name:
.next('div.menu')
// toggles that element:
.toggle("toogle");
});
});
$(文档).ready(函数(){
$('.showmenu')。单击(函数(){
$(this.next('div.menu')。切换(“toogle”);
});
});代码>
点击这里
- 按钮1
- 按钮2
- 按钮3
点击这里
- 按钮1
- 按钮2
- 按钮3
使用next()
。例如:
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next('.menu').toggle("toogle");
});
});
使用next()
。例如:
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next('.menu').toggle("toogle");
});
});
使用next()
。例如:
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next('.menu').toggle("toogle");
});
});
使用next()
。例如:
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next('.menu').toggle("toogle");
});
});
我假设您希望每个div在单击时切换其内容的可见性。选择器将使每个列表嵌套在div下,即使有多个列表
我编辑了你的小提琴。检查一下,您的html中也有一个错误(额外的
)
我假设您希望每个div在单击时切换其内容的可见性。选择器将使每个列表嵌套在div下,即使有多个列表
我编辑了你的小提琴。检查一下,您的html中也有一个错误(额外的
)
我假设您希望每个div在单击时切换其内容的可见性。选择器将使每个列表嵌套在div下,即使有多个列表
我编辑了你的小提琴。检查一下,您的html中也有一个错误(额外的
)
我假设您希望每个div在单击时切换其内容的可见性。选择器将使每个列表嵌套在div下,即使有多个列表
我编辑了你的小提琴。请检查,您的html中也有一个错误(额外的
)。您可以尝试
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next().toggle("toggle");
});
});
你可以试试
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next().toggle("toggle");
});
});
你可以试试
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next().toggle("toggle");
});
});
你可以试试
$(document).ready(function() {
$('.showmenu').click(function() {
$(this).next().toggle("toggle");
});
});
谢谢大卫,帮了大忙!谢谢你的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?查看更新的小提琴,这显然是toggle()
所做的;但是,如果您改用它,它似乎更接近您想要的:。谢谢David!非常感谢,你对自由职业者的机会感兴趣吗?谢谢David的帮助!谢谢你的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?查看更新的小提琴,这显然是toggle()
所做的;但是,如果您改用它,它似乎更接近您想要的:。谢谢David!非常感谢,你对自由职业者的机会感兴趣吗?谢谢David的帮助!谢谢你的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?查看更新的小提琴,这显然是toggle()
所做的;但是,如果您改用它,它似乎更接近您想要的:。谢谢David!非常感谢,你对自由职业者的机会感兴趣吗?谢谢David的帮助!谢谢你的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?查看更新的小提琴,这显然是toggle()
所做的;但是,如果您改用它,它似乎更接近您想要的:。谢谢David!非常感谢,你对自由职业者的机会感兴趣吗?谢谢你的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?请参阅更新的fiddle jsfiddle.net/smnnxn8jI。我不完全确定您的意思。它正在向右扩展以适应div的宽度。如果您希望它向右扩展得更小,请使用css更改div的宽度。谢谢您的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?请参阅更新的fiddle jsfiddle.net/smnnxn8jI。我不完全确定您的意思。它正在向右扩展以适应div的宽度。如果您希望它向右扩展得更小,请使用css更改div的宽度。谢谢您的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?请参阅更新的fiddle jsfiddle.net/smnnxn8jI。我不完全确定您的意思。它正在向右扩展以适应div的宽度。如果您希望它向右扩展得更小,请使用css更改div的宽度。谢谢您的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?请参阅更新的fiddle jsfiddle.net/smnnxn8jI。我不完全确定您的意思。它正在向右扩展以适应div的宽度。如果您希望它向右扩展得更小,请使用css更改div的宽度。谢谢您的帮助。你能解释一下为什么它会向外扩展而不是直接向下吗?看见