我想一個文本行添加到圖像沒有ID或類我有一系列圖像,作爲jQuery的點擊圖片選擇下一個跨度無class和id
<img src="../img/star.png" /><span>no text here until left img is clicked</span>
<img src="../img/someotherpicture.png" /><span>no text here until left img is clicked</span>
<img src="../img/anotherpicture.png" /><span>no text here until left img is clicked</span>
和jQuery的我有
$(document).ready(function(){
$("img").click(function(){
$("img").next.$("span").val("info inserted after clicking on the img next to spa");
})
});
我有點困惑,我應該如何使用未來這裏,也許我應該用找?我總是有一個img,然後是一個跨度。
使用'$回調之內(這).next()。text(「your text goes here」)' – Archer 2013-02-18 19:15:47
jQuery的'.next()'是一個函數,而不是一個屬性,所以你需要圓括號。 http://api.jquery.com/next/ – 2013-02-18 19:16:42
使用您當前的代碼,只能爲所有這些代碼添加相同的文本。必須有一些方法來區分'img'? – nhahtdh 2013-02-18 19:17:16