自定义函数
来源:互联网 发布:js vr 插件 互动 编辑:程序博客网 时间:2024/06/10 16:56
<!doctype html>
<html>
<head>
<title>自定义函数</title>
<!--
之前的Js代码都是一加载就运行, 但是很多时候我们不要一加载就运行, 而需要点击按钮, 链接, 图片才执行
需要有方法的概念: 怎么在JS里面创建方法(函数)
function 函数名(参数1, 参数2, ....){
}
调用:
事件 = 方法();
onclick
利用表单中的name属性来获取对应控件中的值:
-->
<script type="text/javascript">
function testFun (){
alert("调用了testFun()方法");
}
function test (i, d){
alert(i+" -- "+d);
}
function getSum (){
var a = document.myForm.a.value;
var b = document.myForm.b.value;
var c = eval( a + "+" + b );
document.myForm.c.value = c;
}
function getDiv (){
var a = document.myForm.a.value;
var b = document.myForm.b.value;
var c = eval( a + "-" + b );
document.myForm.c.value = c;
}
</script>
</head>
<body>
<input type="button" value=" 测 试 " onclick="testFun()" />
<form name="myForm">
第一个数字: <input type="text" name="a" /><br />
第二个数字: <input type="text" name="b" /><br />
<input type="button" value=" + " onclick="getSum()"/>
<input type="button" value=" - " onclick="getDiv()"/>
<input type="button" value=" * "/>
<input type="button" value=" / "/> <br />
结果:<input type="text" name="c" />
</form>
</body>
</html>
<html>
<head>
<title>自定义函数</title>
<!--
之前的Js代码都是一加载就运行, 但是很多时候我们不要一加载就运行, 而需要点击按钮, 链接, 图片才执行
需要有方法的概念: 怎么在JS里面创建方法(函数)
function 函数名(参数1, 参数2, ....){
}
调用:
事件 = 方法();
onclick
利用表单中的name属性来获取对应控件中的值:
-->
<script type="text/javascript">
function testFun (){
alert("调用了testFun()方法");
}
function test (i, d){
alert(i+" -- "+d);
}
function getSum (){
var a = document.myForm.a.value;
var b = document.myForm.b.value;
var c = eval( a + "+" + b );
document.myForm.c.value = c;
}
function getDiv (){
var a = document.myForm.a.value;
var b = document.myForm.b.value;
var c = eval( a + "-" + b );
document.myForm.c.value = c;
}
</script>
</head>
<body>
<input type="button" value=" 测 试 " onclick="testFun()" />
<form name="myForm">
第一个数字: <input type="text" name="a" /><br />
第二个数字: <input type="text" name="b" /><br />
<input type="button" value=" + " onclick="getSum()"/>
<input type="button" value=" - " onclick="getDiv()"/>
<input type="button" value=" * "/>
<input type="button" value=" / "/> <br />
结果:<input type="text" name="c" />
</form>
</body>
</html>
1 0
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数:
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 自定义函数
- 鲁棒性
- PHP 快速排序法
- 代理模式之静态代理
- poj 3304
- android 调用应用的代码片段
- 自定义函数
- Java多线程学习(吐血超详细总结)
- SMS常见缩写
- malloc底层实现
- 【幻化万千戏红尘】qianfengDay09-java基础学习:接口,抽象类,抽象方法,多态,instanceof
- Android搭建开发环境
- tomcat启动startup.bat一闪而过
- myeclipse和eclipse的区别
- 安卓入门之安卓系统架构