javascript - jQuery mobile listview change select item and highlight it -
in page,there listview,the first item selected:
var len = results.rows.length, $list = $("#listaddr"); var $strhtml =" "; (var = 0; < len; i++) { $strhtml += '<li '; if (i == 0) { $strhtml += ' data-theme="b" '; } $strhtml += '> <a href="#" data-ajax="false"'; $strhtml += ' data-id="' + results.rows.item(i).id + '">' + results.rows.item(i).name + '</a></li>'; } $list.html($strhtml); $list.delegate('li a', 'click',function(e){ // $("#listaddr").attr("li").removeclass("lisel"); $(this).addclass("data-theme='b'"); $("#listaddr").listview("refresh"); //$(this).removeclass("data-theme"); clickaddr($(this).data('id')); });
when select third item,i want third item "data-theme='b'" style , first item remove theme.how able that?
you can soemthing below
$('#listaddr li').bind('click', function () { $('#listaddr li').attr("data-theme", "c").removeclass("ui-btn-up-b").removeclass('ui-btn-hover-b').addclass("ui-btn-up-c").addclass('ui-btn-hover-c'); $(this).attr("data-theme", "b").removeclass("ui-btn-up-c").removeclass('ui-btn-hover-c').addclass("ui-btn-up-b").addclass('ui-btn-hover-b'); });
here example on live fiddle
Comments
Post a Comment