javascript - 如何在图像 src 标签上放置文本
问题描述
我的代码有问题(我还在学习 js)。我想把图片链接到图片src标签,我不知道怎么做,你能帮我吗?
这是我的代码:
$(document).ready(function(){
$(".img").click(function(){
$("#img_link").text($(this).attr('src'));
$('#myModal').modal('hide') ;
});
});
<button type="button" class="btn btn-primary hd" data-toggle="modal" data-target="#myModal">add img</button>
<img id="img_link" src=""/>
解决方案
$(document).ready(function(){
$(".btn").click(function(){
$("#img").attr("src", "https://i.pinimg.com/736x/ab/b6/a8/abb6a800ab2193fcedd9bda566b7402c.jpg");
$("#img_link").text($("#img").attr('src'));
//$('#myModal').modal('hide') ;
});
});
<div class="img_content">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" class="btn btn-primary hd" data-toggle="modal" data- target="#myModal">add img</button>
<p id="img_link"></p>
<img id="img" src=""/>
</div>
推荐阅读
- google-apps-script - 谷歌电子表格减去或添加到行/列
- html - 对齐所有列表项
- node.js - 专门针对猫鼬时间的数据类型
- forms - 以自定义表单呈现一个现有节点字段
- c# - dotnet-SonarScanner - 无法分析 C# 文件
- actionscript-3 - AS3/FLEX 如何扩展 RadioButton 的可点击区域 (mxml)
- angular - 错误:目标入口点“ng-particles”缺少依赖项:- tsparticles
- python - FastAPI auth with jwt,但不是 OAuth2 - 是否可以自定义内置 OAuth2PasswordBearer?
- css - CSS根据页面定位
- powershell - 如何使用命令提示符在 Windows 操作系统的终端中打开新终端