JavaScript中Bom节点和表单的获取值

编程入门 行业动态 更新时间:2024-10-28 13:20:20

JavaScript中Bom<a href=https://www.elefans.com/category/jswz/34/1771452.html style=节点和表单的获取值"/>

JavaScript中Bom节点和表单的获取值

Bom节点

  • 代表浏览器对象模型(Browser Object Model),它是浏览器提供的 JavaScript API,用于与浏览器窗口和浏览器本身进行交互

  • 获取当前网页的URL:

  • const currentURL = window.location.href;
    console.log(currentURL);
  • 设置和获取Cookies:

  • // 设置一个名为 "username" 的 Cookie
    document.cookie = "username=John Doe";
    ​
    // 获取 Cookie 值
    const username = document.cookie;
    console.log(username);
    ​
  • 导航到其他页面:

  • window.location.href = "跳转页面的地址";
  • 获取浏览器信息

  • const web = window.navigator.appName;
    const web_v = window.navigator.appVersion;
    console.log(`浏览器名称: ${web}, 版本: ${web_v}`);

  • id1.style.color = 'red'; //属性使用 字符串 包裹
    id1.style.fonSize = '20px';// 驼峰命名问题
    id1.style.padding = '2em';

    获取表单的获取值

    • 文本框 text

    • 下拉框 <select>

    • 单选框 radio

    • 多选框 checkbox

    • 隐藏框 hidden

    • 密码框 password

    • <form action="post"><P><span>用户名:</span><input type="text" id="username"></P><P><span>性别:</span><input type="radio" name="sex" value="man" id="boy">男<input type="radio" name="sex" value="girl" id="boy">女</P></form><script>let input_text = document.getElementById('username');</script>

    •    输出的语句是input_text.value,将文本框的文字输出

      boy_text.checked 
      true
      girl_text.checked
      false
      • 如上代码: radio的选择框选择男选择框的用checked,不能用value

  • 密码加密

  • <script scr=".10.0/js/md5/2.10.0/js/md5.min.js"></script>//引用mp5加密网站
    </head>
    ​
    <body><form ation="#" method="post"><p><span>用户名:</span><input type="text" id="username" name="username"></p><p><span>密码:</span><!-- password可以让密码隐蔽 --><input type="password" id="password" name="password"></p><!-- 绑定事件onlick被点击 --><button type="submit" onlick="aaa()">提交</button></form><script>function aaa() {let uname = document.getElementById('username');let pwd = document.getElementById('password');console.log(uname.value);console.log(pwd.value);// pwd.value = '*******';pwd.value = md5(pwd.value);console.log(pwd.value);}</script>
    </body>
  • 隐藏密码加密

  • <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script scr=".10.0/js/md5/2.10.0/js/md5.min.js"></script>
    </head>
    ​
    <body><!-- onsubmit=绑定一个提交检测的函数,true ,false 将这个结果返回给表单,使用onsubmit 接收onsubmit = "return aaa()" --><form action="" method="post" onsubmit="return aaa()"><p><span>用户名:</span><input type="text" id="username" name="username"></p><p><span>密码:</span><input type="password" id="input-password" name="password"></p><input type="hidden" id="md5-password" name="password"><button type="submit">提交</button></form>
    ​<script>function aaa() {let name = document.getElementById('username');let pwd = document.getElementById('input-password');let mp5pwd = document.getElementById('md5-password');pwd.value = md5(pwd.value);mp5pwd.value = md5(pwd.value);//将加密的密码在进行隐藏// 可以校验判断表单内容,true就是通过提交,false,阻止提交return true;}</script>

更多推荐

JavaScript中Bom节点和表单的获取值

本文发布于:2023-12-04 09:53:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1660537.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   表单   JavaScript   Bom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!