这当前返回未定义。<option>
注释行中应该包含什么来提醒当前标签的值(1、2、3 或 4) ?
<select id="dropdown" name="dropdown">
<option value="0" data-imagesrc="images/icons/all.png">All Questions</option>
<option value="1" id="friends" data-imagesrc="images/icons/friends.png">Friends</option>
<option value="2" data-imagesrc="images/icons/friends_of_friends.png">Friends of Friends</option>
<option value="3" data-imagesrc="images/icons/network.png"><?php echo $network; ?></option>
<option value="4" data-imagesrc="images/icons/location.png"><?php echo $location ?></option>
</select>
<script type="text/javascript">
$('#dropdown').ddslick({
showSelectedHTML: false,
onSelected: function(selectedData){
var str = $(this).attr('id'); // WHAT SHOULD GO HERE?
alert(str);
}
});
</script>
编辑
如果它是相关的,我正在使用这个插件。
也许这个问题可能会有所帮助。我试图理解它。
设法弄清楚这一点。最终的工作代码是:
<select id="dropdown" name="dropdown" value="hello">
<option value="0" data-imagesrc="images/icons/all.png">All Questions</option>
<option value="1" id="friends" data-imagesrc="images/icons/friends.png">Friends</option>
<option value="2" data-imagesrc="images/icons/friends_of_friends.png">Friends of Friends</option>
<option value="3" data-imagesrc="images/icons/network.png"><?php echo $network; ?></option>
<option value="4" data-imagesrc="images/icons/location.png"><?php echo $location ?></option>
</select>
<script type="text/javascript">
$('#dropdown').ddslick({
showSelectedHTML: false,
onSelected: function(data){
alert(data.selectedData.value);
}
});
</script>