jquery中表單 多選框的一種巧妙寫法,jquery表單

來源:互聯網
上載者:User

jquery中表單 多選框的一種巧妙寫法,jquery表單

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title><link href="css/style.css" rel="stylesheet" type="text/css"/><script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script><script type="text/javascript">$(function(){  $("tbody>tr:odd").addClass("odd");  $("tbody>tr:even").addClass("even");  $('tbody>tr').click(function(){    var hasSelected = $(this).hasClass('selected');    $(this)[hasSelected ? "removeClass" : "addClass"]('selected').find(':checkbox').attr('checked', !hasSelected);  });  $('tbody>tr:has(:checked)').addClass('selected');})</script></head><body><table>  <thead>  <tr>    <th></th>    <th>s</th>    <th>sd</th>    <th>sdasdsa sda</th>  </tr>  </thead>  <tbody>  <tr>    <td><input type="checkbox" name="choice" value=""/></td>    <td>s</td>    <td>s</td>    <td>sdadsadsd</td>  </tr>  <tr>    <td><input type="checkbox" name="choice" value=""/></td>    <td>sadasdsd</td>    <td>s</td>    <td>sads</td>  </tr>  <tr>    <td><input type="checkbox" name="choice" value="" checked='checked'/></td>    <td>sas</td>    <td>s</td>    <td>aasdsad sad</td>  </tr>  <tr>    <td><input type="checkbox" name="choice" value=""/></td>    <td>ss</td>    <td>ssad</td>    <td>dadsadsad</td>  </tr>  <tr>    <td><input type="checkbox" name="choice" value=""/></td>    <td>Rain</td>    <td>sd</td>    <td>sdsad sad asd </td>  </tr>  <tr>    <td><input type="checkbox" name="choice" value=""/></td>    <td>MAXMAN</td>    <td>s</td>    <td>實打實的速度是</td>  </tr>  </tbody></table></body></html>

radio 寫法:

$(function(){  $("tbody>tr:odd").addClass("odd");   $("tbody>tr:even").addClass("even");   $('tbody>tr').click(function(){    $(this).addClass('selected').siblings().removeClass('selected').end().find(':radio').attr('checked', true);  });// $('table :radio:checked').parent().parent().addClass('selected');  $('table :radio:checked').parents("tr").addClass('selected');//$('tbody>tr:has(:checked)').addClass('selected');})

checkbox寫法:

$(function(){  $("tbody>tr:odd").addClass("odd");  $("tbody>tr:even").addClass("even");   $('tbody>tr').click(function(){    if($(this).hasClass('selected')){      $(this).removeClass('selected').find(':checkbox').attr('checked', false);    }else{      $(this).addClass('selected').find(':checkbox').attr('checked', true);    }  });// $('table :checkbox:checked').parent().parent().addClass('selected');  $('table :checkbox:checked').parents("tr").addClass('selected');  //$('tbody>tr:has(:checked)').addClass('selected');})

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.