gpt4 book ai didi

jquery - 使用 jQuery 添加或删除属性来隐藏/显示项目

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

我有以下 jQuery,当我单击按钮时,我用它来隐藏/显示 iFrame。

iFrame 包含一些 PHP,我只想在显示 iFrame 时加载它们。

$(document).ready(function()
{
$('#button').click(function()
{
$('#graphFrame').toggle().attr('src', 'graph1.php');
}
)
}
);

这工作正常,除了当我隐藏 iFrame 时它还会尝试加载 PHP。

有没有办法告诉它在我显示 iFrame(从而加载 php)时添加“src”属性,并在我隐藏 iFrame(从而不加载 PHP)时删除它?

最佳答案

尝试

$('#graphFrame').toggle(function(){
var $this = $(this);
$this.is(":visible") ? $this.attr('src', 'graph1.php') : $this.removeAttr('src')
});

关于jquery - 使用 jQuery 添加或删除属性来隐藏/显示项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16303881/

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