开发者

jQuery - change row background in function

I have a simple table and I have an checkbox at the end of every line. My concept is to when the user clicks the checkbox send some information to a function and then use AJAX to perform a task. That is straightforward but I want to be then change the background of the row so it is visually obviously it has been selected.

All the rows have a label of tr_xxx (where the xxx is the id from a table), so for example

<tr id="row_74539"> For the checkbox I have an onclick event:

onclick="AddItem(entry_<?php echo $row_Recordset1['EntryNo']; ?>.value,sale_<?php echo $row_Recordset1['EntryNo']; ?>.value)

which is fine and at the moment my function just shows an alert so I can check the data being passed:

function AddItem(entry,sale)
    {
        var chk = 0;
        if ( eval("document.form1.checkbox_"+entry+".checked") )
                  chk = 1;
        alert("entry"+entry+" sale "+sale+" checkbox "+ chk);
        //$(therow).addClass('darkclass');
         $('tr tr_'+entry).css('background-color', '#FFFF99');


    };

The problem and I am sure I am being stupid is to change the 开发者_如何转开发colour of the background - that is the last line of the function.


Your Selector:

$('tr 'tr_'+entry)

I would drop the first tr and give that a try.


function AddItem(entry,sale){ 
var chk = 0; 
if ($('input:checkbox[name=checkbox_'+entry+']:checked')) 
    chk = 1;

alert("entry"+entry+" sale "+sale+" checkbox "+ chk);
//$(therow).addClass('darkclass'); 
$('tr').find('#tr_'+entry).css('background-color', '#FFFF99');
}

I think this will server your purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜