Javascript and CSS if statement
Javascript and CSS if statement
我对编程非常陌生,我正在尝试编写一个代码,该代码只会在没有按下ctrl键的情况下显示图像。
<script language=JavaScript>
document.onkeydown = checkKey;
var Showimg = False;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '17') {
alert('test');
Showimg = True;
}
}
</script>
这是我目前得到的代码。我在下面的另一个部门有代码,其中有图像的代码。
我对CSS和javascript很陌生,基本上对大多数编码都很陌生,所以我不确定如果按下ctrl键,是否可以让图像不再显示,因为"if"语句似乎在脚本外不起作用,但图像代码在脚本内不起作用。
这可能不够详细,对不起。
因此,您可以按下事件部分来确定何时按下ctrl键。您现在需要的(除了其他人指出的一些语法问题之外)是使用javascript来隐藏图像。首先,您需要一种识别它的方法,例如,您可以添加img的id(或其他)。
<img id="img">
然后,您可以使用js来实现这一目标,并更改if语句中的display属性。
document.getElementById('img').style.display = 'none';
此代码将a)查找图像,b)将显示更改为不显示。
function checkKey(e) {
e = e || window.event;
console.log(e);
if (e.keyCode === 17) {
document.getElementById('image').style.display = 'none';
}
}
function show() {
document.getElementById('image').style.display = 'block';
}
让身体像一样
<body onkeydown="checkKey()" onkeyup="show()">
对于图像,你可以把它做成这个
<img src="test.jpg" id="image">
相关文章:
- Jquery else if statement
- Rails 3 if statement with jQuery?
- JQuery Else if statement?
- 在jQuery .load Ajax之后执行if-statement
- Javascript if statement if (ball.style.left === '0px'
- If-Statement中的Javascript元素验证
- Javascript document.cookie if statement
- Javascript Logic In a loop/if statement
- Javascript if statement Google Tools
- Javascript IF statement
- ActionScript 3 If/ Else If Statement
- Javascript if-statement vs. comparsion
- Javascript condense if statement
- 嵌套的 if's:使用 if (x) {statement;} 还是 if (!x) 返回更好;陈述;
- Javascript optimizing if statement
- Javascript and CSS if statement
- JQUERY, AJAX if else statement
- Vuejs IF statement
- Datatables Find Replace If Statement
- javascript msgbox if statement