[英]How to put text on image src tag
i have problem with my code (i'm still studying js).我的代码有问题(我还在学习 js)。 I wanna put link from image to images src tag, I don't know how to do this can you help me?
我想把图片链接到图片src标签,我不知道怎么做,你能帮我吗?
this is my code:这是我的代码:
$(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>
You would have to use,你必须使用,
$("#img_link").attr('src', 'the text you want to go into src')
As you did not provide all the code I think the text would be由于您没有提供所有代码,我认为文本将是
$(this).text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.