在下面的代碼上需要幫助。我不想替換我在“a:contains”中呼叫的文本。問題是我需要在哪里將::before放在下面的腳本中。
鏈接:https ://jsfiddle.net/onw7aqem/
$(document).ready(function() {
$("a:contains(This is the text)").css("content", "url('https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U')");
});
<a href="#">This is the text</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
uj5u.com熱心網友回復:
考慮以下。
$(function() {
$("<div>").css("content", "url('https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U')").appendTo($("a:contains(This is the text)"));
});
<a href="#">This is the text</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
這將創建一個<div>元素并將其附加到該<a>元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/456342.html
標籤:javascript html jQuery css 阿贾克斯
