zoukankan
html css js c++ java
关于使用JS修改图片地址的一点困惑
今天在使用JS切换图片时遇到一点问题。
<
script
>
function
show(id)
{
var
o
=
this
.document.getElementById('line'
+
id);
var
t
=
this
.document.getElementById('
switch
'
+
id);
//
var img=new Image();
//
初始代码没有new 一个Image对象
var
img
=
this
.document.getElementById('img'
+
id);
if
(o.style.display
==
'none')
{
o.style.display
=
'';
t.innerText
=
'收缩';
img.src
=
'
/
images
/
page
/
webshop
/
001
/
48_2.gif';
}
else
{
o.style.display
=
'none';
t.innerText
=
'展开';
img.src
=
'
/
images
/
page
/
webshop
/
001
/
48
.gif';
}
}
</
script
>
初始代码没有new Image对象(注意这里Image对象,首字母大写),结果图片显示总是空白。思考了一下发现了原因。
修改代码后,发觉可以正常显示了。不过还有一点困惑的地方是,有的时候还是图片没有出来,可能过一会儿就好了,
这是感到比较奇怪的地方!
作者:
Jackhuclan
出处:
http://jackhuclan.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
查看全文
相关阅读:
Linux安装RabbitMQ3.8.7
VS安装Resharper,使用IDEA风格的快捷键,还需修改的快捷键
Spring Boot Starter开发
windows安装redis集群
spring为bean指定InitMethod和DestroyMethod的三种方法
spring注入的方式总结
bean运行时值注入
CodeForces 1569C Jury Meeting
CodeForces 1569B Chess Tournament
CodeForces 1569A Balanced Substring
原文地址:https://www.cnblogs.com/jackhuclan/p/883903.html
最新文章
数据库基础
使用for循环打印爱心
eclipse字体大小设置
导入数组工具依赖包报错The import java.util.Arrays conflicts with a type defined in the same file
JDK 8 的安装与配置
JavaSE_语言概述
zookeeper 启动报 系统找不到指定的路径。 Error: JAVA_HOME is incorrectly set 错误的快速解决办法
SQLException: The server time zone value '�й���ʱ��' is unrecognized 解决办法
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platfor
iview组件select无法手动设置值
热门文章
跳转到前端路由外的页面返回接口所获取的值不对
vue动态绑定background:url绑不上的问题
踩过的坑
安装jdk设置环境变量(win10)
微信x5内核很鸡贼啊
Unexpected character '�' (1:0) while parsing file
ios下,<input type="checkbox"> 点击时出现黑色块
使用dos命令行远程复制文件到windows服务器
gradle配置
ELK安装使用
Copyright © 2011-2022 走看看