javascript - JS function receives parameters and pops up
怪我咯
怪我咯 2017-07-05 10:52:48
0
2
660
<!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>
  1. Can I alert pop out the content in the box at once?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
阿神

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梦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!