怎么在html的<img src="">src的值这里调用js方法或变量获取图片地址

本文介绍了一种使用JavaScript动态加载图片的方法,并提供了具体的HTML与JavaScript代码实现。通过设置图片元素的src属性,可以实现网页中图片的动态加载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<html>

<head>参考自

</head>

<body>

<img src="?"  id="img">

</body>

<script language="javascript">

var adres="图片地址";

document.getElementById('img').src = adres;

</script>

</html>

参考自https://bbs.youkuaiyun.com/topics/390732020/ 

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>前端网-登录注册</title> </head> <body> <h1>wasai</h1> <p id="p1">不错</p> <img src="1.jbg" alt="示例图片"> <table border="1"> <caption>用户信息表</caption> <tr> <th>序号</th> <th>姓名</th> <th>性别</th> <th>年龄</th> </tr> <tr> <td>1</td> <td>张三</td> <td>男</td> <td>18</td> </tr> <tr> <td>2</td> <td>王五</td> <td>男</td> <td>22</td> </tr> </table> <br> <a href="login.html">登录</a> <form action="login.php" method="post" onsubmit="return test()"> <script> function test() { const username = document.getElementById('username').value; const password = document.getElementById('password').value; alert(`用户名:${username}\n密码:${password}`); return false; // 阻止表单提交 } </script> <label>用户:<input type="text" id="username" name="username" required></label><br> <label>密码:<input type="password" id="password" name="password" required></label><br> 男:<input type="radio" name="sex" value="male" required> 女:<input type="radio" name="sex" value="female"><br> 打游戏:<input type="checkbox" name="hobby[]" value="gaming"> 听音乐:<input type="checkbox" name="hobby[]" value="music"> 看小说:<input type="checkbox" name="hobby[]" value="novel"><br> <select id="city" name="city"> <option value="chengdu">成都</option> <option value="guangan">广安</option> <option value="beijing">北京</option> </select> <input type="file" name="file"> <textarea id="comment" name="comment" rows="5" cols="20"></textarea> <input type="submit" value="提交"> <button type="button">注册</button> </form> <script src="test.js"></script> </body> </html> 添加if来判断密码输入错误
03-09
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chde2Wang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值