区域变色,方法的采纳详解

作者: 韦德国际1946国际网址  发布:2019-05-28
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    <html xmlns="http://www.w3.org/1999/xhtml">  <head>      <title></title>      <script src="JS/jquery-1.4.1.min.js" type="text/javascript"></script>      <style type="text/css">          * { margin:0; padding:0; text-align:center;}          body {TEXT-ALIGN: center;}          #center { MARGIN-RIGHT: auto; MARGIN-LEFT: auto; }      </style>      <script type="text/javascript">          $(document).ready(function () {              var canvers = document.getElementById("diagonal");              var context = canvers.getContext("2d");              context.globalAlpha = 0.5;                $("#Map area").each(function () {                  $(this).mouseover(function () {                        context.beginPath();                      var strs = new Array(); //定义一数组                      strs = $(this).attr("coords").split(",");                      var i1, i2;                      for (var i = 0; i < strs.length; i  ) {                          if (i % 2 == 0) {                              i1 = strs[i];                          }                          if (i % 2 == 1) {                              i2 = strs[i];                              if (i == 1) {                                  context.moveTo(i1, i2);                              }                              else {                                  context.lineTo(i1, i2);                              }                          }                      }                      context.fillStyle = "#C0C0C0";                      context.fill();                        context.closePath(); //闭合                  });                  $(this).mouseout(function () {                      context.clearRect(0, 0, 750, 528);                  });              });          });      </script>  </head>  <body>      <div id="center"  >          <div  Images/map.png') repeat scroll 0% 0% transparent; padding: 0px; width: 750px; height: 528px; position: relative;">                              <canvas id="diagonal"   width="750px" height="528px"></canvas>              <img src="images/map.png" width="750px" usemap="#Map"  />              <map id="Map" name="Map">                  <area alt="北部区域"   data_ID="1" coords="564,222,552,229,545,243,545,248,523,249,518,240,521,238,523,235,525,227,522,224,521,207,526,207,526,200,523,194,524,189,520,185,486,147,486,144,483,142,484,134,488,130,493,130,497,132,507,132,518,122,527,121,535,116,538,111,541,109,546,109,551,103,556,104,564,101,569,104,575,104,575,97,570,92,566,92,561,86,553,86,549,89,533,90,531,92,527,90,528,80,530,72,535,61,540,61,541,63,548,63,552,59,556,59,565,54,565,51,562,48,564,46,565,42,569,38,570,31,575,21,576,13,572,10,582,2,596,6,605,7,608,9,612,13,612,15,620,22,627,20,633,18,637,23,645,33,649,34,649,41,652,44,653,51,655,53,662,52,670,51,677,52,681,56,684,56,688,62,692,64,694,71,704,71,707,68,711,68,722,59,736,54,736,67,733,73,733,87,730,106,720,105,713,106,710,110,709,116,714,121,716,137,714,139,711,141,709,145,706,145,704,141,700,142,700,150,697,152,695,155,685,157,685,161,688,163,687,167,673,167,670,162,667,163,666,165,665,170,659,179,652,182,647,189,645,192,639,194,635,197,624,201,616,209,608,210,608,208,611,206,610,198,615,195,611,181,603,182,597,188,595,193,589,196,582,197,581,202,580,207,579,209,563,209,562,212,561,217" shape="poly">                  <area alt="东部区域"   data_ID="2" coords="582,424,584,417,566,411,566,415,547,414,544,416,542,412,546,407,535,403,535,393,532,384,527,377,529,369,533,363,532,351,538,345,547,344,550,339,561,338,561,331,558,329,558,320,551,319,551,316,556,307,557,304,554,299,549,299,543,292,550,283,553,277,560,280,563,277,563,272,559,272,560,270,561,264,565,266,570,266,582,268,585,270,589,270,590,268,598,273,608,278,612,289,606,294,607,298,611,300,620,300,632,309,621,310,611,307,628,316,623,322,627,324,623,329,612,332,631,333,637,337,631,343,637,344,631,347,633,352,633,355,637,360,626,359,626,367,622,369,621,374,617,377,619,381,614,385,608,381,614,389,610,402,604,411,596,409,596,414,589,414,590,422" shape="poly">                  <area alt="西部区域"   data_ID="3" coords="17,147,21,144,19,136,26,135,32,126,39,126,40,122,43,125,49,125,50,129,54,132,62,128,73,125,84,120,98,120,108,120,114,111,124,103,122,97,123,87,120,79,131,79,139,83,144,80,150,84,152,75,166,60,172,64,181,66,191,69,195,57,201,49,208,50,217,42,225,43,225,52,243,69,251,79,253,86,245,100,248,108,263,111,275,114,285,123,294,127,295,133,303,148,316,151,328,152,335,155,348,156,359,157,391,171,400,171,404,174,423,167,437,162,448,165,458,163,468,162,487,147,519,186,510,190,506,193,500,192,497,196,487,200,485,204,478,202,473,205,469,205,456,221,456,225,450,228,442,225,438,225,435,224,429,233,439,242,444,242,456,246,451,251,453,256,446,258,441,262,437,266,429,265,423,269,422,283,420,286,415,287,414,293,420,297,429,296,436,303,444,303,447,306,454,304,459,308,466,312,476,322,472,330,462,328,455,332,458,336,459,343,467,348,464,354,461,358,464,353,458,366,451,358,452,353,446,353,440,349,435,352,427,352,421,358,417,356,413,360,420,367,415,371,407,370,405,370,405,367,402,365,399,366,395,363,390,367,388,358,381,356,379,361,375,365,375,371,368,375,367,392,360,391,356,393,347,383,346,377,337,369,336,363,329,361,322,350,319,352,317,356,315,352,314,347,308,345,307,351,300,358,296,358,295,353,289,354,287,361,281,360,271,353,265,351,247,359,240,358,236,362,235,363,235,366,228,368,222,364,217,362,210,362,209,355,204,352,203,346,193,346,184,339,180,338,170,343,170,350,166,350,163,346,163,344,166,339,165,338,159,337,159,340,156,340,155,338,141,338,137,331,134,331,134,334,130,334,130,330,128,330,127,332,124,332,123,328,120,325,117,324,117,322,115,322,115,319,116,318,110,317,108,312,103,306,100,306,97,308,94,307,108,312,103,306,100,306,97,308,94,306,95,303,84,292,83,288,77,284,73,283,70,288,67,288,58,275,55,276,54,271,47,266,43,263,44,259,45,252,43,250,42,248,43,244,47,241,48,246,53,246,56,241,54,232,54,225,61,222,56,217,54,210,54,201,46,202,41,197,32,190,32,184,35,181,19,170,27,162,27,155,30,151,27,149,25,146,18,146" shape="poly">                                                                                               <area alt="南部区域"   data_ID="4" coords="532,351,529,343,525,343,521,345,518,344,515,339,511,340,509,340,504,335,500,336,496,339,493,339,492,337,487,337,481,343,479,342,473,342,467,348,464,354,461,358,464,353,458,366,451,358,452,353,446,353,440,349,435,352,427,352,421,358,417,356,413,360,420,367,415,371,407,370,405,370,405,367,402,365,399,366,395,363,390,367,388,358,381,356,379,361,375,365,375,371,368,375,367,392,360,391,356,393,347,383,346,377,337,369,336,363,329,361,322,350,319,352,317,356,315,352,314,347,308,345,307,351,300,358,296,358,296,362,301,362,304,366,304,381,301,384,301,388,284,404,285,410,283,415,290,411,299,411,299,424,301,427,309,427,303,437,303,441,312,442,319,452,326,452,327,449,333,449,333,458,343,458,343,449,342,441,352,441,355,437,358,440,364,440,368,438,378,441,378,437,387,438,395,432,408,438,420,438,419,443,416,449,437,458,444,458,448,455,454,458,460,458,467,459,465,469,468,472,469,475,461,479,458,482,448,488,449,496,462,503,479,496,479,488,484,480,477,475,477,471,473,466,488,459,496,458,499,454,504,455,504,452,514,452,514,450,523,450,522,439,529,447,536,447,540,441,544,444,546,441,552,438,568,436,582,424,584,417,566,411,566,415,547,414,544,416,542,412,546,407,535,403,535,393,532,384,527,377,529,369,533,363" shape="poly">                  <area alt="中部区域"   data_ID="5" coords="519,186,510,190,506,193,500,192,497,196,487,200,485,204,478,202,473,205,469,205,456,221,456,225,450,228,442,225,438,225,435,224,429,233,439,242,444,242,456,246,451,251,453,256,446,258,441,262,437,266,429,265,423,269,422,283,420,286,415,287,414,293,420,297,429,296,436,303,444,303,447,306,454,304,459,308,466,312,476,322,472,330,462,328,455,332,458,336,459,343,467,348,473,342,479,342,481,343,487,337,492,337,493,339,496,339,500,336,504,335,509,340,511,340,515,339,518,344,521,345,525,343,529,343,532,351,538,345,547,344,550,339,561,338,561,331,558,329,558,320,551,319,551,316,556,307,557,304,554,299,549,299,543,292,550,283,553,277,560,280,563,277,563,272,559,272,560,270,561,264,565,266,570,266,582,268,585,270,589,270,590,268,591,262,606,247,619,236,628,235,629,230,621,230,617,231,613,229,600,228,592,238,585,238,581,234,582,225,573,225,565,226,564,222,552,229,545,243,545,248,523,249,518,240,521,238,523,235,525,227,522,224,521,207,526,207,526,200,523,194,524,189,520,185" shape="poly">              </map>          </div>      </div>  </body>  </html>  

uibutton点击过的区域在下二个页面变色
自个儿刚学ios,使用的是swift语言,怎样使uibutton点击过的区域在下一个页面展现成铜锈绿区域,未点击的不变颜色

jquery.map()方法的运用详解,jquery.map使用详解

原型方法map跟each类似调用的是同名静态方法,只可是重回来的数码必须通过另2个原型方法pushStack方法管理现在才回去,源码如下:

map: function( callback ) {
    return this.pushStack( jQuery.map(this, function( elem, i ) {
      return callback.call( elem, i, elem );
    }));
  },

正文主要正是深入分析静态map方法至于pushStack在下一篇小说里面剖判;

区域变色,方法的采纳详解。率先驾驭下map的应用(手册内容)

$.map将一个数组中的成分转变来另1个数组中。

用作参数的转移函数会为各种数组成分调用,而且会给那个转变函数字传送递二个表示被转变的要素作为参数。

退换函数能够回来调换后的值、null(删除数组中的项目)或2个包蕴值的数组,并扩张至原始数组中。

参数
arrayOrObject,callbackArray/Object,FunctionV1.6
arrayOrObject:数组或然指标。

为各类数组成分调用,而且会给那一个转变函数传递3个代表被转变的要素作为参数。

函数可回到任何值。

别的,此函数可设置为三个字符串,当设置为字符串时,将视为“lambda-form”(缩写方式?),个中a 代表数组成分。

如“a * a”代表“function(a){ return a * a; }”。

示例1:

//将原数组中每个元素加 4 转换为一个新数组。
//jQuery 代码:
$.map( [0,1,2], function(n){
 return n   4;
});
//结果:
[4, 5, 6]

示例2:

//原数组中大于 0 的元素加 1 ,否则删除。
//jQuery 代码:
$.map( [0,1,2], function(n){
 return n > 0 ? n   1 : null;
});
//结果:
[2, 3]

示例3:

//原数组中每个元素扩展为一个包含其本身和其值加 1 的数组,并转换为一个新数组
//jQuery 代码:
$.map( [0,1,2], function(n){
 return [ n, n   1 ];
});
//结果:
[0, 1, 1, 2, 2, 3]

能够见见map方法跟each方法类似通过巡回每一种对象大概数组的“项”试行回调函数来兑现对数组也许指标的操作,可是那四个点子也是有数不胜数不一样点

比方each()再次来到的是本来的数组,并不会新创设多少个数组,而map则会创立新的数组,;each遍历是this指向当前数组或对象值,map则指向window,因为在源码中并不像each那样使用对象冒充;

例如:

var items = [1,2,3,4]; 
$.each(items, function() { 
alert('this is '   this); 
}); 
var newItems = $.map(items, function(i) { 
return i   1; 
}); 
// newItems is [2,3,4,5]
//使用each时,改变的还是原来的items数组,而使用map时,不改变items,只是新建一个新的数组。

var items = [0,1,2,3,4,5,6,7,8,9]; 
var itemsLessThanEqualFive = $.map(items, function(i) { 
// removes all items > 5 
if (i > 5) 
  return null; 
  return i; 
}); 
// itemsLessThanEqualFive = [0,1,2,3,4,5]

言归正传回到map源码

// arg is for internal usage only
  map: function( elems, callback, arg ) {
    var value, key, ret = [],
      i = 0,
      length = elems.length,
      // jquery objects are treated as arrays
      isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;

    // Go through the array, translating each of the items to their
    if ( isArray ) {
      for ( ; i < length; i   ) {
        value = callback( elems[ i ], i, arg );

        if ( value != null ) {
          ret[ ret.length ] = value;
        }
      }

    // Go through every key on the object,
    } else {
      for ( key in elems ) {
        value = callback( elems[ key ], key, arg );

        if ( value != null ) {
          ret[ ret.length ] = value;
        }
      }
    }

    // Flatten any nested arrays
    return ret.concat.apply( [], ret );
  },

第壹照旧注解多少个变量为接下去的遍历做图谋,当中jsArray变量用来大致区分对象和数组,这么些布尔复合表明式相比长不过如果记住js运算符的有优先顺序就轻易通晓了,首先括号优先实施然后便是逻辑与》逻辑或》全等》赋值,然后就能够分析啦

先是圆括号里先总括然后结果加上 length !== undefined 、 typeof length === "number那三个要求条件最终的结果再跟elems instanceof jQuery进行逻辑或的运算,简单来讲就是isArray为真的气象有:

一、elems instanceof jQuery  为true 换言之正是jquery对象

2、length !== undefined && typeof length === "number" 和  length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems )这八个至少营造三个

能够拆分为一个小动静

length是存在并且是数字还要待遍历的数组可能类数组等length属性大于0 length-一存在  那样就有限协理了是能遍历的,举个例子对于jquery对象  domList对象等

length是存在并且是数字还要length属性等于0  借使是0也没提到正是不会遍历

length是存在并且是数字并且待遍历对象是纯数组

知足那么些规则之后起首按照isArray的结果分开遍历,对于“数组”选择for循环,对于目的采取for...in循环

// Go through the array, translating each of the items to their
    if ( isArray ) {
      for ( ; i < length; i   ) {
        value = callback( elems[ i ], i, arg );

        if ( value != null ) {
          ret[ ret.length ] = value;
        }
      }

是数组只怕类数组的时候一直把循环的每一项的值和指针以及arg参数字传送入回调函数中实行,arg参数是此措施内部使用的参数,跟each以及一些任何jquery方法很相像,只要在施行回调函数时不回来null就把实行回来的结果增多到新数组中,对象操作亦是如此直接略过

// Flatten any nested arrays
    return ret.concat.apply( [], ret );

最终将结果集扁平化,为何有这一步呢?因为map是足以扩大数组的在眼下第二个示范就是那样:

$.map( [0,1,2], function(n){
 return [ n, n   1 ];
});

设要是那般使用的话赢得的新数组是一个2维数组,所以必须降维

 ret.concat.apply( [], ret )等价于[].concat.apply([],ret)关键功效的是apply,因为apply的第一个参数把ret的数组分成五个参数字传送入给concat把二维数组转化为1维数组那些用法依旧值得珍藏的的

map方法简便剖判达成,才具有限错误之处望多多指正。

以上所述正是本文的全体内容了,希望我们可以喜欢。

原型方法map跟each类似调用的是同名静态方法,只可是重返来的数据必须透过另贰个原型方法...

近年在讲AJAX方面包车型客车1对抵触和在品种中的应用。笔者介绍到了AJAX的一些里头原理,以及两套AJAX框架:Microsoft ASP.NET AJAX和jquery.


自家个人很欣赏Jquery,作者对它的赞誉从不吝啬。呵呵

至于Jquery,其实前面就写过繁多,有乐趣的可以参照

本文由韦德国际1946发布于韦德国际1946国际网址,转载请注明出处:区域变色,方法的采纳详解

关键词: 区域 页面 uibutton 伟德国际官方