zoukankan      html  css  js  c++  java
  • 9章 表单[js] —— javaScript宝典

    9.1 form对象

    form对象

    document.forms[0]

    使用元素名称的字符串作为数组下标

    document.forms[“formName”]

    注意:数组引用单词的复数形式

    另外可以使用表单名 document.formName

    9.1访问表单属性

    document.forms[0].action = ”http://www.howia.net” ;  //改变属性直接赋值

    document.formName.target

     

    9.2作为对象的表单控件

    例如

    <form name="searchForm">
    <input type="text" name="entry">
    <input type="submit" name="sender" value="Serach">
    </form>

    对文本输入控件以下都有效

    document.searchForm.entry
    document.searchForm.elements[0]
    document.forms["searchForm"].elements["entry"]
    document.forms["searchForm"].entry

    9.2.2按钮对象

    9.2.3复选框对象

    9.2.4单选框对象

    读取组的按钮数

    document.forms[0].groupName.length

    想查询某个按钮是否高亮显示【check属性】

    document.forms[0].groupName.checked

    9.2.5 Select对象

    select最重要属性selectedIndex

    selectedIndex 属性可设置或返回下拉列表中被选选项的索引号

    document.forms[0].selectName.selectedIndex

    其中2个重要属性text和value

    doucument.forms[0].selectName.options[n].text

    doucument.forms[0].selectName.options[n].value

    function goThere()
    {
        var list=document.forms[0].urlList;
        location.href=list.options[list.selectedIndex].value;
    }

    9.3向函数传递表单数据和元素

    (1) onchange="upperMe(this)"

    接收端,函数定义一个参数变量将引用转换为变量,这个变量可以被函数的其他语句使用

    finction upperMe(filed){

    statment[s]

    }

    (2)可以使用this关键字来引用当前控件,再加上form属性,如this.form

    onclick="inspact(this.form)"

    函数定义应该有一个参数变量被赋值为form对象引用,用户可以确定变量名或不用变量名,我们倾向于使用form变量名,以提醒用户所引用变量

    function inspact(form){

    statment[s]

    }

    9.4提交和预验证表单

    document.forms[0].submit();

  • 相关阅读:
    myeclipse中jpa的安装以及jpa reverse engining
    myeclipse显示db-brower
    jpa报错 Unable to acquire a connection from driver [null], user [null] and URL [null]
    sqlserver安装和踩坑经历
    idea注释模板
    可选链与空值合并
    Nokia5130不能上网
    血小板 live2d web使用
    什么值得买前端面试题 2019秋季
    便利蜂前端面试题 2019秋季
  • 原文地址:https://www.cnblogs.com/tangge/p/2082184.html
Copyright © 2011-2022 走看看