jQuery的prop和attr练习切换图片
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>18-attr和prop的练习</title> <script src="../js/jquery-1.12.4.js"></script> <script> $(function () { //1.给我们的按钮天界点击事件 var btn=document.getElementsByTagName("button")[0]; btn.onclick=function () { //2.获取输入框输入的内容 var input=document.getElementsByTagName("input")[0]; var text=input.value; //3.修改img的src属性节点的值 // $("img").attr("src",text); $("img").prop("src",text); } }) </script></head><body><input type="text"><button>切换图片</button><br><img src="https://www.baidu.com/img/bd_logo1.png" ></body></html>
相关推荐
84483065 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
tztzyzyz 2020-07-05
delmarks 2020-06-28
89510194 2020-06-27
牵手白首 2020-06-14
tztzyzyz 2020-05-31
81463166 2020-05-17
88570299 2020-05-17
delmarks 2020-05-17
donghongbz 2020-05-15
tztzyzyz 2020-05-15
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%&qu
牵手白首 2020-05-14
Chriswang 2020-04-30
83510998 2020-05-03