JS 借鉴

javascript中Onchange是什么意思? onchange 事件常结合对输入字段的验证来使用。 当用户改变输入字段的内容时,触发事件。

<html> <body style="font-size:12px"> 性别<br> 男<input type="radio" name="radio" value="1" onclick="radio_click(this)"> 女<input type="radio" name="radio" value="2" onclick="radio_click(this)"> 未定义<input type="radio" name="radio" value="3" onclick="radio_click(this)"> <script type="text/javascript"> function radio_click(obj){     var sex=(obj.value=='1'?'男':(obj.value=='2'?'女':'未定义'));     alert("你选中的性别是 '"+sex+"'"); } </script> </body> </html>

js中onclick事件,可以调用两个方法吗? function a(){    alert(1);   }   function b(){    alert(2);   }   <input type="button" onclick="a();b();" value="ab"/>

<input type="text" name="" id=""/>中的name和id有什么区别? name 是表单提交后,给后台处理程序区分不同的输入框。

例如 name = '用户名' name =‘密码’,后台程序就会分别去处理用户名和密码。

而 id 通常给前台程序,例如 Javascript,CSS,让它去为不同 id 的输入框设置不同的响应动作,风格样式等。但这些前台语言,有的时候也支持对 name 的识别。

id 是不会提交给后台的,所以后台一定只能用 name 去识别。

Document 对象 每个载入浏览器的 HTML 文档都会成为 Document 对象。 Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问。 提示:Document 对象是 Window 对象的一部分,可通过 window.document 属性对其进行访问。

onsubmit="return checkForm();" 这句代码什么意思? 提交表单的时候先执行checkForm();这个方法,如果这个方法返回的是false则将不提交表单.

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>用户表单验证</title>

<script>

  function changeValue(){

  var userName=document.getElementById("userName"); //通过Id获得对象userName;

 userName.value=userName.value.toUpperCase();  //将对象的值进行大小写的转换赋值给当前对象的值;

  } </script> </head> <body>

<form name="myform" method="POST" action="register.php" onsubmit="return checkForm();">

userName:<input type="text" name="userName" value="" id="userName" onchange="changeValue();" /><br/>

<input type="submit" name="" value="用户注册" /> </form> </body> </html>

<FORM id=form name=form onsubmit= return checkform()这段代码是什么意思? 定义一个form表单,表单名和id都是form。当提交表单时执行checkform函数来对表单进行验证。

<form name="form1" method="POST" action="a.asp" onsubmit="return checkform();"> <input type="text" name="thistimemoney" id="yanzi" size="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue = false;"> <input type="submit" value="确定并开始" name="submit"> </form> 函数定义: <script language=javascript> function checkform(){ if (form1.thistimemoney.value==""){ alert("你没输入钱数啊!"); document.getElementById("yanzi").focus(); return(false); } } </script>

 

posted on 2015-03-24 09:49  小甜瓜安东泥  阅读(136)  评论(0)    收藏  举报