//页面级内容
<button id="div1">时间</button>
img id="myimage" src="./img/LIS1.png" onclick="time()" width="300px" height="300px"/>
//JS中内容
function time() {
//换图
ele = document.getElementById("myimage"); //获取dom
console.log(ele.src.match("LIS1")); //通过ele.src.match("LIS1")获取图片路径
if (ele.src.match("LIS1")) {
ele.src = "./img/LIS2.png";
} else {
ele.src = "./img/LIS1.png";
}
// innerHTML = "段落已修改。" //是用于修改元素的 HTML 内容(innerHTML)的 JavaScript 代码。
// document.getElementById('div1').innerHTML =new Date().getTime()
//innerHTML是来渲染一个标签文本
//new Date().getTime() 时间戳 获取当前时间
}
【在JS中如何获取图片路径以及更改图片】
最新推荐文章于 2023-07-28 09:30:14 发布