2012-06-21 63 views
0
//activate selected row in table 
jQuery('.activatebutton').click(function(){ 
    var tb = jQuery(this).attr('title'); 
    //initialize to false as no selected row 
    var sel = false; 
    //get each checkbox in a table 
    var ch = jQuery('#'+tb).find('tbody input[type=checkbox]'); 

    //check if there is/are selected row in table 
    ch.each(function(){ 
    if(jQuery(this).is(':checked')) { 
     //set to true if there is/are selected row 
     sel = true; 
    jQuery(this).parents('tr').fadeOut(function(){ 
     /* 
     THIS IS THE LINE THAT IS NOT WORKING BELOW!!!! I want to send VALUE ID to delete.php 
     */ 
     jQuery.get('delete.php', { id:this.id }); 
     //remove row when animation is finished 
     jQuery(this).remove(); 
    }); 
    } 
}); 
+0

你是说delete.php没有被请求或id参数没有被发送到delete.php? – JeremyWeir

+0

我的第一个建议是使用带有控制台(Firefox和Firebug或Chrome)的浏览器并插入一行'console.log(“ID =”+ this.id);''jQuery.get(' delete.php'...'这可以让你看到什么,如果有的话,ID值被拾取并发送到你的delete.php脚本。 –

+0

@JeremyWeir delete.php没有被请求,但它可能是因为id参数没有被发送,对吧? – user1470755

回答

1

不清楚你想要发送什么属性,但看起来它是元素的id。如果是这样,这里的地方修正为:

jQuery.get('delete.php', { id:this.id }); 

应该

jQuery.get('delete.php', { id:jQuery(this).attr('id') }); 

所以你要派元素的id属性。

如果这仍然不起作用,您可能会有删除脚本的路径不正确...... chrome开发工具或萤火虫会告诉你这一点。

+0

你可以访问id而不用调用jQuery对象。 (实际上,使用'this.id'而不是'jQuery(this).attr('id')')会稍微快一点。所以这是一个错误的解决方案。 - 请参阅http://stackoverflow.com/questions/4651923/when-to-use-vanilla-javascript-vs-jquery –

+0

是的。这下滑了我的想法。应该已经进入我的答案的第二部分更多:) – unceus