0
問:我想在img「src」屬性的末尾添加「-hvr」,當我關注輸入類型文本並刪除當字段沒有對焦時,「-hvr」。下面是我使用jQuery的代碼,但它不工作:我想使用jquery在img「src」屬性的末尾添加「-hvr」
$('.signup-fld > input').click(function() {
var imgAttr = $(this).parent().find('img').attr('src').replace(/\.jpg/, '-hvr.jpg');
$(this).attr("src", imgAttr);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="signup-fld">
<img src="img/user-form-ico.jpg" />
<input type="text" placeholder="Full name" />
</div>
<div class="signup-fld">
<img src="img/pass-form-ico.jpg" />
<input type="text" placeholder="Full name" />
</div>
謝謝!這很有幫助。 –