任何人都可以解释以下代码吗?
function showImage(){
var imgs = $('#gallery img');
imgs.live('click', function(){
var title = $(this).attr('title');
$('#picture h1').text(title);
$('#pic').html($(this).clone());
$.mobile.changePage($('#picture'));
});
}
答案 0 :(得分:0)
代码将click事件处理程序附加到所有img元素,并在单击时显示单个img。
// get all img elements in #gallery
var imgs = $('#gallery img');
// bind a click handler on all img elements
imgs.live('click', function(){
// get the title attribute of the clicked img
var title = $(this).attr('title');
// set h1 text to title and add the clicked img to our new page
$('#picture h1').text(title);
$('#pic').html($(this).clone());
// switch to the new page
$.mobile.changePage($('#picture'));
});
我认为单个img页面看起来像这样:
<div data-role="page" id="picture">
<div data-role="content">
<h1></h1>
<div id="pic"></div>
</div>
</div>