一旦激活其中一个事件,如何禁用其他onclick事件.两个div都设置为display:none; 在CSS中.这可能很简单,但我是编程新手.
HTML
<a id="leftbutton" href="#" onclick="showDiv(this.id); return false;">click me</a>
<a id="righttbutton" href="#"onclick="showDiv(this.id); return false;">click me</a>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
function showDiv(id)
{
if(id == "leftbutton"){
document.getElementById('orangediv').style.display = 'block';
}else{
document.getElementById('greendiv').style.display = 'block';
}}
Run Code Online (Sandbox Code Playgroud) 我正在研究从摄氏温度到华氏温度,从华氏温度到摄氏温度的简单转换形式.我无法弄清楚它为什么不转换.
HTML
<head>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<form name="tempForm">
<label for="temp">Temperature:</label>
<input type="text" id="temp"><br>
<input type="radio" name="choice" value="fahrenheit" checked />Convert to Fahrenheit <br>
<input type="radio" name="choice" value="celsius">Convert to Celsius <br>
<label for="resultField">Result: </label>
<input type="text" id="resultField"><br>
<input type="button" value="Convert" onclick="processForm()">
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
Javascript函数processForm(){
var temperature = Number(document.tempForm.temp.value);
var tempType;
var result;
for (var i=0; i < document.tempForm.choice.length; i++) {
if (document.tempForm.choice[i].checked) {
tempType = document.tempForm.choice[i].value;
}
}
if (tempType == 'fahrenheit') {
result = temperature * 9/5 + 32; …Run Code Online (Sandbox Code Playgroud)