2012-04-04 8 views

答えて

4

次のことを試してみてください。

$('li > a[href="#"][data-value]').click(function (e) { // On click of all anchors with a data-value attribute and a href of # that are immediate children of li elements (nb this selector can be modifed to suit your needs) 
    e.preventDefault(); // prevent the default (navigate to href) 
    refreshGrid($(this).data('value')); // call your refreshGrid function with the value contained in the 'data-value' attribute 
}); 
1
var linkValue = $("li a").attr("data-value"); 

編集:より良い例

$("li a").click(function() { 
    var myDataValue = $(this).attr("data-value"); 
    refreshGrid(myDataValue); 
}); 
1

here's a quick sample

$('ul').on('click','a[data-value]',function(){ 
    refreshGrid(this.getAttribute('data-value')); 
    return false; 
}); 
関連する問題