Created
May 25, 2017 10:48
-
-
Save greatghoul/9a8b3ec7b0293ec96ab96a5b6ff71d47 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/luhoho
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style> | |
table { text-align: center; } | |
.name { display: inline-block; width: 60px; background-color: #ccc; height: 16px;} | |
</style> | |
<script> | |
function fill(button) { | |
document.getElementById(button.className).innerHTML = button.innerHTML; | |
} | |
function call() { | |
var nameA = document.getElementById('a').innerHTML; | |
var nameB = document.getElementById('b').innerHTML; | |
var formulas = { | |
'爸爸爸爸': '爷爷', | |
'爸爸妈妈': '奶奶', | |
'妈妈爸爸': '外公', | |
'妈妈妈妈': '外婆', | |
}; | |
var result = formulas[nameA + nameB]; | |
document.getElementById('result').innerHTML = result; | |
} | |
</script> | |
</head> | |
<body> | |
<table border="1" width="100%"> | |
<tr> | |
<td> | |
<button class="a" onclick="fill(this)">爸爸</button> | |
<button class="a" onclick="fill(this)">妈妈</button> | |
</td> | |
<td> | |
<button class="b" onclick="fill(this)">爸爸</button> | |
<button class="b" onclick="fill(this)">妈妈</button> | |
</td> | |
</tr> | |
<tr> | |
<td colspan="2"> | |
<span class="name" id="a"></span> | |
的 | |
<span class="name" id="b"></span> | |
<button onclick="call()">叫</button> | |
<span class="name" id="result"></span> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment