<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>函数接收参数并弹出</title>
<style type="text/css">
body {font: 12px/1.5 Tahoma; text-align: center;}
input {border: 1px solid #ccc; padding: 3px;}
button {cursor: pointer;}
</style>
<script type="text/javascript">
var myFn = function(a,b) {
alert(a.value);
alert(b.value)
};
window.onload = function() {
var oInput = document.getElementsByTagName("input");
var oBtn = document.getElementsByTagName("button")[0];
oBtn.onclick = function() {
myFn(oInput[0],oInput[1])
}
};
</script>
</head>
<body>
<p><input type="text" value="北京市"></p>
<p><input type="text" value="朝阳区"></p>
<p><button>传参</button></p>
</body>
</html>
Can I alert
pop out the content in the box at once?
阿神2017-07-05 10:54:48
Can’t. One sentence of alert() pops up the alert box once.
After closing an alert box, the next alert box will pop up.
You can concatenate two input values into a string, for example:
var myFn = function(a,b) {
var str = a.value + ',' + b.value;
alert(str);
};
过去多啦不再A梦2017-07-05 10:54:48
Can’t.
The pop-up window is executed synchronously. When alert(a.value);
is called, the system will no longer execute (blocked). The pop-up window must be closed before the following code can continue to execute.
So, the solution is not to use the alert
function, but to use a third-party pop-up window, which can pop up multiple ones at the same time.