- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
全局变量的值var img_id = 2;在点击功能中更改。稍后它可能会在另一个函数中使用,我想要该变量的更改值,以防在按钮函数之前使用点击函数。但是即使在它之前使用了 clicked 函数,它仍然显示值 2。
function switchVisible() {
if (document.getElementById('mapButtons')) {
if (document.getElementById('mapButtons').style.display == 'none') {
document.getElementById('mapButtons').style.display = 'block';
document.getElementById('modelButtons').style.display = 'none';
}
else {
document.getElementById('mapButtons').style.display = 'none';
document.getElementById('modelButtons').style.display = 'block';
}
}
}
function flip() {
$('.side').toggleClass('rotated');
}
window.img_id = 2;
$(function() {
$('area').mouseover(function() {
imgid=$(this).data('imgid');
// $('#demo').text("Mouseover for "+imgid);
$('#'+imgid)
.toggleClass('invert',true)
.css('z-index',2);
}).mouseout(function() {
imgid=$(this).data('imgid');
// $('#mi').text("Mouseout for "+imgid);
$('#'+imgid)
.toggleClass('invert',false)
.css('z-index',1);
}).click(function() {
imgid=$(this).data('imgid');
//$('#demo').text("click for "+imgid);
$('.pressed').removeClass('pressed');
img_id= imgid;
// $('#d').text("new function "+img_id);
$('#'+imgid)
.toggleClass('pressed')
.css('z-index',2);
});
});
$(function() {
img = img_id;
$('#d').text("new function "+img_id);
//var img = 2;
var min = 2;
var max = 12;
$('.prevButton').on('click',function(e) {
if (img > min) {
removeAllBorders();
img--;
$('#' + img).toggleClass('pressed');
}
});
$('.nextButton').on('click',function(e) {
if (img < max) {
removeAllBorders();
img++;
$('#' + img).toggleClass('pressed');
}
});
function removeAllBorders() {
$('img').removeClass('pressed');
}
});
#container img {position: absolute;}
img.invert {
filter: invert(100%);
-webkit-filter: invert(100%);
-moz-filter: invert(100%);
-o-filter: invert(100%);
-ms-filter: invert(100%);
}
img.pressed {
filter: invert(100%);
-webkit-filter: invert(100%);
-moz-filter: invert(100%);
-o-filter: invert(100%);
-ms-filter: invert(100%);
}
.side {
position: absolute;
-webkit-transition:-webkit-transform 0.5s;
-moz-transition: -moz-transform 0.5s;
-o-transition: -o-transform 0.5s;
transition: transform 0.5s;
-webkit-backface-visibility:hidden;
-moz-backface-visibility:hidden;
-ms-backface-visibility:hidden;
-o-backface-visibility:hidden;
backface-visibility:hidden;
}
.side.rotated {
-webkit-transform:rotateY(360deg);
-moz-transform:rotateY(360deg);
-ms-transform:rotateY(360deg);
-o-transform:rotateY(360deg);
transform:rotateY(360deg);
}
.back {
-webkit-transform:rotateY(180deg);
-moz-transform:rotateY(180deg);
-ms-transform:rotateY(180deg);
-o-transform:rotateY(180deg);
transform:rotateY(180deg);
}
#mapButtons { position:absolute;top:90%;}
#modelButtons {
display: none;
position:absolute;top:90%;
}
.block {
width: 100%;
height: 100%;
-webkit-perspective:100%;
-moz-perspective:100%;
-ms-perspective:100%;
-o-perspective:100%;
perspective:100%;
}
#flip-button {
background: white;
font-family:'open sans';
font-weight: 400;
color: #5b5b5b;
border-radius: 5px;
margin-top: 1em;
}
.prevButton img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.prevButton:hover img {
opacity: .5;
}
.nextButton img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.nextButton:hover img {
opacity: .3;
}
<body>
<map name="map" id="id_1">
<div id="container">
<div class="front side">
<img src="leftovers_ch01.png" style='position:absolute;top:8;left:9;z-index:1' usemap="#map" >
<img id="2" class="myBorder" src="http://i.imgur.com/fpqmClk.png" style='z-index:1' usemap="#map" >
<img id="3" class="myBorder" src="http://i.imgur.com/TfhyWZs.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="4" class="myBorder" src="http://i.imgur.com/mUKWK5P.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="5" class="myBorder" src="http://i.imgur.com/R1JhAT9.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="6" class="myBorder" src="http://i.imgur.com/yMGFR2V.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="7" class="myBorder" src="http://i.imgur.com/rpCnGxL.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="8" class="myBorder" src="http://i.imgur.com/FWRCUs4.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="9" class="myBorder" src="http://i.imgur.com/Aw3NhT9.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="10" class="myBorder" src="http://i.imgur.com/gWhUtyJ.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="11" class="myBorder" src="http://i.imgur.com/IIJqsxf.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
<img id="12" class="myBorder" src="http://i.imgur.com/a9UW5mj.png" style='position:absolute;top:8;left:9; z-index:1' usemap="#map" >
</div>
<area data-imgid="12" shape="poly" coords="173,223,176,222,183,224,185,217,190,199,193,192,198,187,193,176,158,132,126,92,132,93,123,79,101,97,81,123,66,149,57,170,50,194,48,211,136,217,131,225,149,225,149,221,152,221,156,215,158,208,159,197,167,189,170,179,173,177,169,171,190,176,192,187,190,190,182,198"
/>
<area data-imgid="11" shape="poly" coords="173,229,181,229,184,243,192,256,201,265,201,271,179,309,174,302,125,375,106,361,88,342,71,319,59,295,52,270,48,252,47,243,65,240,61,248,147,234,147,236,150,234,150,238,154,234,154,239,156,235,159,246,165,262,175,275,185,284,195,270,184,259,177,249,174,237,173,229"
/>
<area data-imgid="10" id="ch10" coords="208,268,220,272,234,272,249,266,253,272,235,280,223,280,214,279,215,274,202,283208,298,209,295,222,297,239,296,251,293,261,288,259,293,262,290,262,296,264,294,65,298,266,295,276,310,266,309,304,389,285,398,259,404,241,406,210,407,187,402,169,398,152,390,158,373,162,380,203,273,208,268"
/>
<area data-imgid="9" class="notbutton" id="ch09" class="hotspot" shape="poly" coords="252,265,255,266,256,271,267,262,275,249,279,233,296,234,291,255,282,270,272,280,268,283,274,284,270,286,274,288,271,290,275,291,272,292,328,359,319,359,331,374,349,360,366,342,381,321,392,299,400,276,404,257,407,240,318,235,323,227,278,227,272,231,269,244,262,256,252,265"
/>
<area data-imgid="8" class="notbutton" id="ch08" class="hotspot" shape="poly" coords="251,188,253,181,267,192,273,200,277,208,278,212,274,213,288,220,298,207,294,207,289,196,284,186,274,174,262,166,268,166,266,164,270,162,267,161,270,159,266,158,276,142,279,151,329,78,338,85,349,94,363,108,379,129,391,152,397,168,403,189,406,211,389,213,393,206,277,225,272,222,269,209,262,197,251,188"
/>
<area data-imgid="7" class="notbutton" id="ch07" class="hotspot" shape="poly" coords="247,186,248,182,251,179,239,175,228,173,216,174,206,177,199,161,213,157,225,156,239,157,254,162,254,158,256,159,257,155,258,157,259,152,260,154,292,72,296,79,302,63,286,56,263,50,242,47,213,47,188,51,166,57,149,64,188,143,179,143,201,181,208,185,218,182,236,182,247,186"
/>
<area data-imgid="6" class="notbutton" id="ch06_09" shape="poly" coords="156,234,156,226,154,222,154,226,150,223,150,226,147,224,148,227,130,227,135,220,47,213,31,223,16,212,15,226,16,236,16,243,33,254,48,243,66,240,61,248,148,233,147,236,151,234,151,237,153,234,154,239,156,234"
/>
<area data-imgid="6" class="notbutton" id="ch06_08" shape="poly" coords="173,230,173,227,180,224,184,228,180,230,173,230"
/>
<area data-imgid="6" class="notbutton" id="ch06_07" shape="poly" coords="205,264,207,268,203,272,162,380,158,372,151,389,154,407,136,417,124,412,115,406,108,401,125,394,125,375,174,302,179,309,200,271,201,266,205,264"
/>
<area data-imgid="6" class="notbutton" id="ch06_06" shape="poly" coords="261,288,260,291,263,290,262,295,264,293,264,297,266,295,275,309,266,309,305,389,321,397,319,415,330,412,341,405,347,400,347,379,330,374,318,359,328,359,272,292,274,291,271,289,275,288,269,287,273,284,267,284,261,288"
/>
<area data-imgid="6" class="notbutton" id="ch06_05" shape="poly" coords="249,264,249,268,253,273,256,271,254,266,249,264"
/>
<area data-imgid="6" class="notbutton"id="ch06_04" shape="poly" coords="271,227,273,223,277,225,393,206,388,214,407,211,420,200,436,210,438,218,438,229,437,242,422,231,406,240,318,235,323,227,277,227,274,230,271,227"
/>
<area data-imgid="6" class="notbutton" id="ch06_03" shape="poly" coords="256,163,262,166,267,165,265,164,269,162,266,161,269,159,266,158,276,142,279,150,329,78,329,59,344,51,333,45,323,39,316,36,300,45,303,63,296,80,292,72,260,154,259,153,259,158,256,155,257,159,254,158,256,163"
/>
<area data-imgid="6" class="notbutton" id="ch06_02" shape="poly" coords="248,189,247,183,251,180,253,181,252,186,248,189"
/>
<area data-imgid="6" class="notbutton" id="ch06_01" shape="poly" coords="199,191,203,188,207,192,205,187,207,185,202,182,178,142,188,143,149,64,133,55,133,37,122,44,112,49,107,53,107,73,123,78,135,93,126,93,199,183,199,191"
/>
<area data-imgid="5" class="notbutton" id="ch05_06" shape="poly" coords="16,212,31,223,47,214,50,189,55,169,62,152,70,136,81,120,92,107,105,93,118,82,123,79,107,73,107,54,91,65,73,83,57,101,45,119,36,137,27,158,20,183,17,202,16,212"
/>
<area data-imgid="5" class="notbutton"id="ch05_05" shape="poly" coords="108,401,125,394,125,375,112,366,97,352,83,336,69,316,61,298,54,280,49,261,47,243,33,255,16,244,20,270,27,293,34,313,45,334,57,352,71,369,88,385,108,401"
/>
<area data-imgid="5" class="notbutton" id="ch05_04" shape="poly" coords="305,389,321,398,319,415,290,427,265,433,237,436,208,436,181,432,159,426,136,417,154,407,151,391,171,399,192,404,213,407,236,407,261,404,280,399,296,393,305,389"
/>
<area data-imgid="5" class="notbutton" id="ch05_03" shape="poly" coords="406,240,423,231,437,242,434,264,429,285,424,302,416,320,404,341,390,360,375,376,357,391,347,399,347,380,331,374,345,363,358,350,370,336,380,323,387,309,395,294,399,279,403,265,406,247,406,240"
/>
<area data-imgid="5" class="notbutton"id="ch05_02" shape="poly" coords="329,77,328,58,344,52,363,66,383,85,396,101,410,123,421,144,428,164,433,182,436,199,436,210,420,200,406,211,404,191,398,169,390,149,380,131,365,110,352,97,339,86,329,77"
/>
<area data-imgid="5" class="notbutton" id="ch05_01" shape="poly" coords="132,55,134,37,152,30,174,23,200,18,219,17,240,17,260,19,276,22,291,26,303,31,316,36,300,45,303,63,284,55,265,51,250,48,234,46,215,47,194,49,175,53,157,60,149,64,132,55"
/>
<area data-imgid="5" class="notbutton" id="ch04_03" shape="poly" coords="195,270,185,284,174,273,166,263,160,251,157,240,156,226,158,211,163,195,174,180,177,177,174,175,191,176,192,191,188,189,178,203,173,219,173,233,177,248,185,261,195,270"
/>
<area data-imgid="4" class="notbutton" id="ch04_02" shape="poly" coords="202,283,215,275,214,279,223,280,234,280,245,277,257,271,265,264,273,253,278,241,280,233,296,235,290,257,283,269,276,276,267,285,251,292,235,297,220,297,210,295,209,298,202,283"
/>
<area data-imgid="4" class="notbutton" id="ch04_01" shape="poly" coords="206,177,216,174,231,173,247,177,257,183,266,191,273,201,278,212,274,213,288,220,297,207,294,208,289,196,282,184,271,172,260,165,245,159,230,156,214,157,199,161,206,177"
/>
<area data-imgid="2" id="ch02" shape="poly" coords="214,234,216,246,228,241,238,246,240,233,248,227,239,219,237,207,226,212,216,208,215,219,205,227,214,234"
/>
<area data-imgid="3" id="ch03" shape="poly" coords="181,226,189,227,181,229,182,237,186,247,192,256,199,262,203,266,207,261,206,267,213,270,222,272,232,272,242,269,250,266,247,262,251,266,259,259,265,251,269,242,272,234,272,227,267,227,272,226,271,218,269,209,264,201,257,193,250,188,247,191,247,187,239,182,226,181,214,183,207,186,205,187,208,194,203,188,196,193,189,201,184,211,181,221,181,226"
/>
</map>
<div class="back side">
<img id="image1" src="blbl.png" style='position:absolute;top:8;left:9;' usemap="#map2" />
</div>
</div>
<p id="demo"></p>
<p id="mi"></p>
<p id="clicked"></p>
<div id = "mapButtons" >
<button class = "prevButton" type="button"><img id="image" src="http://i.imgur.com/PjVnMY1.png"></button>
<button id="flip-button" class = "changeButton" type="button" onclick= "flip();switchVisible();"><img id="image" src="mapButton1.png"></button>
<button class = "nextButton" type="button"><img id="image" src="http://i.imgur.com/sR3xfJl.png"></button>
</div>
<div id = "modelButtons" >
<button class = "prevButton" type="button"><img id="image" src="prevButton.png"></button>
<button id="flip-button" class = "changeButton" type="button" onclick= "flip(); switchVisible();"><img id="image" src="modelButton1.png"></button>
<button class = "nextButton" type="button" ><img id="image" src="nextButton.png"></button>
</div>
<p id="d"></p>
</body>
最佳答案
问题或原因:
第二个 function() block 在 main 函数 block 内执行 img = img_id
,它执行一次,然后在初始页面加载后不再执行。它还定义了一些事件处理程序,但它们都使用 img
的值 不再更改 ... 只有事件处理程序被多次调用,但代码没有在他们之前。
解决方法:
在这些事件处理程序中直接使用 img_id
。
关于javascript - javascript中的全局变量在函数中使用后不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36014829/
C语言sscanf()函数:从字符串中读取指定格式的数据 头文件: ?
最近,我有一个关于工作预评估的问题,即使查询了每个功能的工作原理,我也不知道如何解决。这是一个伪代码。 下面是一个名为foo()的函数,该函数将被传递一个值并返回一个值。如果将以下值传递给foo函数,
CStr 函数 返回表达式,该表达式已被转换为 String 子类型的 Variant。 CStr(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CSng 函数 返回表达式,该表达式已被转换为 Single 子类型的 Variant。 CSng(expression) expression 参数是任意有效的表达式。 说明 通常,可
CreateObject 函数 创建并返回对 Automation 对象的引用。 CreateObject(servername.typename [, location]) 参数 serv
Cos 函数 返回某个角的余弦值。 Cos(number) number 参数可以是任何将某个角表示为弧度的有效数值表达式。 说明 Cos 函数取某个角并返回直角三角形两边的比值。此比值是
CLng 函数 返回表达式,此表达式已被转换为 Long 子类型的 Variant。 CLng(expression) expression 参数是任意有效的表达式。 说明 通常,您可以使
CInt 函数 返回表达式,此表达式已被转换为 Integer 子类型的 Variant。 CInt(expression) expression 参数是任意有效的表达式。 说明 通常,可
Chr 函数 返回与指定的 ANSI 字符代码相对应的字符。 Chr(charcode) charcode 参数是可以标识字符的数字。 说明 从 0 到 31 的数字表示标准的不可打印的
CDbl 函数 返回表达式,此表达式已被转换为 Double 子类型的 Variant。 CDbl(expression) expression 参数是任意有效的表达式。 说明 通常,您可
CDate 函数 返回表达式,此表达式已被转换为 Date 子类型的 Variant。 CDate(date) date 参数是任意有效的日期表达式。 说明 IsDate 函数用于判断 d
CCur 函数 返回表达式,此表达式已被转换为 Currency 子类型的 Variant。 CCur(expression) expression 参数是任意有效的表达式。 说明 通常,
CByte 函数 返回表达式,此表达式已被转换为 Byte 子类型的 Variant。 CByte(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CBool 函数 返回表达式,此表达式已转换为 Boolean 子类型的 Variant。 CBool(expression) expression 是任意有效的表达式。 说明 如果 ex
Atn 函数 返回数值的反正切值。 Atn(number) number 参数可以是任意有效的数值表达式。 说明 Atn 函数计算直角三角形两个边的比值 (number) 并返回对应角的弧
Asc 函数 返回与字符串的第一个字母对应的 ANSI 字符代码。 Asc(string) string 参数是任意有效的字符串表达式。如果 string 参数未包含字符,则将发生运行时错误。
Array 函数 返回包含数组的 Variant。 Array(arglist) arglist 参数是赋给包含在 Variant 中的数组元素的值的列表(用逗号分隔)。如果没有指定此参数,则
Abs 函数 返回数字的绝对值。 Abs(number) number 参数可以是任意有效的数值表达式。如果 number 包含 Null,则返回 Null;如果是未初始化变量,则返回 0。
FormatPercent 函数 返回表达式,此表达式已被格式化为尾随有 % 符号的百分比(乘以 100 )。 FormatPercent(expression[,NumDigitsAfterD
FormatNumber 函数 返回表达式,此表达式已被格式化为数值。 FormatNumber( expression [,NumDigitsAfterDecimal [,Inc
我是一名优秀的程序员,十分优秀!