您的位置:首页 > Web前端 > JavaScript

Js函数接收参数并弹出对话框

2015-03-05 18:16 316 查看
一个JavaScript小教程:Js函数接收参数并弹出对话框,可将Input输入框中的值传入函数中,再由函数读取显示,这里使用Alert函数弹出框来显示接收到的值,相信对学习JavaScript的朋友有用处吧?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>函数接收参数并弹出</title>

<style>

body{font:12px/1.5 Tahoma;text-align:center;}

code,input,button{font-family:inherit;}

input{border:1px solid #ccc;padding:3px;}

button{cursor:pointer;}

</style>

<script>

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: