开发者

need to change the class of a table row when a checkbox is check the table is made dynamically using php and mysql

i need the tr to change background 开发者_开发问答color, text color and have a line through the txt.

To-Do Item Priority Due Date " value="checked" />


You have a much better chance of getting your question answered if you clean up the formatting, and ask a clear question. To clarify, do you want to dynamically set it to a predefined class that has the font attributes you're trying to set on it, or is it enough to change the item's "style" attribute to have these elements?

At the very least, your checkbox will need some javascript attached to it. This would be an example of the input generated for row 1 of the table--row 2 would have "t_row_2", etc. (all generated by PHP).

Put this script somwhere in a header:

<script type="text/javascript">
function setClass(chkbox,row_id){
  row = document.getElementById(rowid);
  if(row){
    if(elem.checked){
      row.setAttribute("class","checkedClassName");
    }else{
      row.setAttribute("class","uncheckedClassName");
    }
  }
}
</script>

This is what the input should would look like using this method:

<input type="checkbox" id="chk" onclick="setClass(this,'t_row_1)" />

If you're not afraid to play a little more with the javascript, and assuming your checkbox is within the tr in question, you can get rid of the row id parameter with a "getParentTr" function:

<script type="text/javascript">
function getParentTr(elem){
  parent = elem.parentNode;
  while(parent !== document.body){
    if(parent.type === "tr"){
      return parent;
    }
  }
  return null;
</script>

Then you would remove the second parameter from the "setClass" function above, and replace "row = document.getElementById(rowid);" with "row = getParentTr(elem);"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜