gpt4 book ai didi

javascript - jQuery : Remove created element if CLICKED button value is xxx

转载 作者:行者123 更新时间:2023-12-03 02:47:02 25 4
gpt4 key购买 nike

我创建了一个 div(其中包含内容)onclick “信息按钮”,并且使用 将值 “信息按钮” 更改为“返回” $("#").toggle();

现在我之前创建的 div 没有被删除,尽管我有这个

if ($(this).val() == '返回') {$('#msg').remove();}

这是我的代码;

$("#InformationButton").one('click',function () {



$('<div>stackoverflow -- dynamically created content</div> ', {
id: 'Interface',
text: ''}).appendTo('#main-section');
$("#Interface").toggle("slow", "linear");


})

$('.InformationButton').click(function () {

$(".PageBody").fadeToggle("fast", "linear");

$(this).val($(this).val() == 'Information button' ? 'Go Back' : 'Information button');
$("#Interface").toggle();

});

$('.InformationButton').click(function () {

if ($(this).val() == 'Go Back') {
$('#Interface').remove();
}

});

如果用户单击信息按钮和 id 值 ==“Go Back”并显示 .PageBody,我需要删除 #Interface

最佳答案

$('.ImpToExcel').click(function () { 内,这指的是具有类 .ImpToExcel 的单击元素。

您需要保存对this的引用

$("#InformationButton").one('click',function () {
$self = $(this);


//rest of the code

$('.ImpToExcel').click(function () {

//rest of the code
$self.val($self.val() == 'Information button' ? 'Go Back' : 'Information button');
//rest of the code
});

});

关于javascript - jQuery : Remove created element if CLICKED button value is xxx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48061666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com