我是 javascript 和英语不好的新手。
1)我有这样的HTML:
<ul id="search-list" class="playlist1">
<li class="song songW" data-song-id="70">
<div id="songNum" class="songNum" songurl="music/turn-it-up.mp3"
songtitle="Turn It Up">Turn It Up
</div>
</li>
<li class="song songB" data-song-id="83">
<div id="songNum" class="songNum" songurl="music/black-keys.mp3"
songtitle="Black Keys">Black Keys </div>
</li>
</ul>
2)我使用这个 Javascript 从点击的 DIV 中获取属性有 class 或 id = "songNum" :
var el = $("ul#search-list");
$(el).bind(".songNum").click(function(eve) {
eve.preventDefault();
songUrl = $(this).attr("songurl");
alert(songUrl);});
///// It's return "Undefined"
3)当我改变
var el = $("ul#search-list");
$(el).bind(".songNum").click(function(eve) {
eve.preventDefault();
songUrl = $(".songNum").attr("songurl");
alert(songUrl); });
///// It's just return a atrribute of the first DIV =>"music/turn-it-up.mp3", even i was click on the second DIV
请帮助我,告诉我我的错误!十分感谢 !!!