gpt4 book ai didi

javascript - 在加载时隐藏图像并根据一个 url 参数值显示

转载 作者:行者123 更新时间:2023-11-27 23:54:00 25 4
gpt4 key购买 nike

该页面有图像,并且这些图像必须在加载时隐藏,当页面从另一个aspx页面接收到参数值后(不单击任何按钮),图像将根据一个参数值显示。这段代码可以成功接收数据,但是如何使用参数值来隐藏和显示图像?

HTML:

 <input type="button" id="mybutton" />
<script>
$('#mybutton').click(function () {
$.ajax({
url: 'About.aspx',
dataType: 'text',
type: "GET",
success: function(data)
{
var result = $.trim(data);
if (result = 2) {
$("image1").show();

} else {

if (result = 3) {

$("image2").show();
}
}
}
});
});
</script>

<div id="graphic">
<img id="gate1" src="Img/Fully Close Green.png" />
<img id="gate2" src="Img/Fully Close Red.png" />
</div>

最佳答案

尝试此代码在文档就绪事件中隐藏图像,或使用css类设置display:none,然后使用image1设置图像的用户ID和 image2# 标签用于访问任何元素的 id,. 用于类以进行更多检查 This :-

$(function () {
$('#graphic img').hide();
$.ajax({
url: 'About.aspx',
dataType: 'text',
type: "GET",
success: function (data) {
var result = $.trim(data);
if (result == 2) {
$("#gate1").show();

} else if (result == 3) {
$("#gate2").show();
}
//you can put more options here or just use else condition instread of else if
}
});
});

关于javascript - 在加载时隐藏图像并根据一个 url 参数值显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32431143/

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