我有一個片段,我試圖與之合作;我有幾個產品,我抓住了源代碼,將它拆分爲「?」並將其放入數組中,然後用新鏈接替換「img.item-img」src。
但是,我沒有使用循環或$('this')來區分它們的唯一性。所以如果我有三個項目,他們都獲得第一個src代碼。
<script>
$(document).ready(function() {
$("img.item-img").each(function() {
str = $("img.item-img").attr('src');
arr = str.split("?");
var new_link = arr[0];
$("img.item-img").attr('src', new_link);
});
</script>
你的問題是? – BenM
你的問題是什麼?因爲你說過你不用'$(this)',但爲什麼不呢? (這是我的問題......) –