1. 程式人生 > >jquery函數封裝

jquery函數封裝

oct type head back bsp set ons move urn

<script type="text/javascript">
  $(function () {
    $("#tabMenu a").on(‘click‘,function () {
  obj(this);

  });
  $(‘#tabCon a‘).on(‘click‘,function () {
    obj(this);
  });
  function obj(e){
    $(e).addClass(‘current‘).siblings().removeClass(‘current‘);
    var value = $(e).data(‘value‘);
    $(e).parent().find(‘input‘).val(value);
  }
})
</script>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="odd">奇數</div>
    <div id="even">偶數</div>
    <script type="text/javascript">
        var arr= [1,2,3
,4,5,6,7,8,9,10] function getId(id) { return document.getElementById(id) } var odd = getId("odd") var even = getId("even") odd.onclick = function(){ obj(1) } even.onclick = function(){ obj(0) }
function obj(e){ for (var i = 0; i < arr.length; i++) { if (arr[i] % 2 == e) { console.log(arr[i]) } } } </script> </body> </html>

jquery函數封裝