9999热视频三级毛片AV区|日韩欧美精品狼友观看视频|av在线成人免费AA片|日韩三级AV电影|久久亚洲私人国产精品vA|亚洲无码卡一卡二卡三|手机在线免费看黄色片|婷婷尹人在线婷婷五月手机网|99爱在线播放|欧美成人色情视频品

jquery checkbox無法用attr()二次勾選問題的解決方法
來源:易賢網(wǎng) 閱讀:1587 次 日期:2016-07-29 15:06:10
溫馨提示:易賢網(wǎng)小編為您整理了“jquery checkbox無法用attr()二次勾選問題的解決方法”,方便廣大網(wǎng)友查閱!

下面小編就為大家?guī)硪黄猨query checkbox無法用attr()二次勾選問題的解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。

比如,如下HTML頁面,一點【選中】、二點【取消選中】、三點【選中】,瞧,不行了唄。

1.html

<!doctype html>

<html lang="en">

<head>

 <meta charset="utf-8">

 <title>prop demo</title>

 <style>

 img {

  padding: 10px;

 }

 div {

  color: red;

  font-size: 24px;

 }

 </style>

 <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>

<body>

 <input type="checkbox" checked="checked">

 <input type="checkbox">

 <input type="checkbox">

 <input type="checkbox" checked="checked">

<script>

$( "input[type='checkbox']" ).prop( "checked", function( i, val ) {

 return !val;

});

</script>

</body>

</html>

解決方案,是使用prop()替換attr()方法(在Jquery1.6以上),如下代碼:

2.html

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Attr checked</title>

<script type="text/javascript" src="./js/jquery-1.11.2.js"></script>

<script type="text/javascript">

  function switchChecked(flag) {

    $("input[type='checkbox']").prop('checked', flag);

  }

</script>

</head>

<body>

  <input type="checkbox" />

  <input type="button" onclick="switchChecked(true)" value="選中">

  <input type="button" onclick="switchChecked(false)" value="取消選中">

</body>

</html>

以上這篇jquery checkbox無法用attr()二次勾選問題的解決方法就是小編分享給大家的全部內(nèi)容了

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:jquery checkbox無法用attr()二次勾選問題的解決方法
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)