当前位置:网站首页>js中#号的作用
js中#号的作用
2022-07-03 03:29:00 【南风~古草】
1、#代表id选择器
如 $("#LUsername").val();(拿到对应id对象的值)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<label>
<span>用户名</span>
<input type="text" id="LUsername" />
</label>
<label>
<span>密码</span>
<input type="password" id="LPassword"/>
</label>
<button type="button" class="submit" id="login" onclick="return check();">登 录</button>
</div>
</body>
<script type="text/javascript" src="js/jquery-3.6.0.min.js"></script>
<script>
function check(){
var username = $("#LUsername").val();/*拿到id为LUsername的input输入框对应的值*/
var password= $("#LPassword").val();/*拿到id为LPassword的input输入框对应的值*/
console.log("用户名:"+username)
console.log("密码:"+password)
}
$(function () {
document.onkeydown=keyDownSearch;
function keyDownSearch(e) {
var theEvent = e || window.event;
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
if(code==13){
$('#login').click();
return false;
}
return true;
}
})
</script>
</html>
上述代码中,用js完成了对登录按钮的简单监听。
点击登录按钮后,按钮上的onclick会去调用check()函数,通过id选择器拿到对象后取其中的值。
将值在Console控制台输出。
边栏推荐
- Limit of one question per day
- ffmpeg之 一张/多张图片合成视频
- com. fasterxml. jackson. databind. Exc.invalidformatexception problem
- 程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
- The calculation of stripe, kernel and padding in CNN
- MongoDB簡介
- User value is the last word in the competition of mobile phone market
- 机械臂速成小指南(八):运动学建模(标准DH法)
- 静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
- 递归:快速排序,归并排序和堆排序
猜你喜欢
Vs Code configure virtual environment
UMI route interception (simple and rough)
Ansible简介【暂未完成(半成品)】
Use of El tree search method
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
Limit of one question per day
The series of hyperbolic function in daily problem
Pytorch轻量级可视化工具wandb(local)
Pytoch lightweight visualization tool wandb (local)
[pyg] understand the messagepassing process, GCN demo details
随机推荐
The idea cannot be loaded, and the market solution can be applied (pro test)
Hi3536c v100r001c02spc040 cross compiler installation
FileZilla client download and installation
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
navicat 导出数据库的表结构
程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
解决高並發下System.currentTimeMillis卡頓
leetcode:动态规划模板
VS 2019 配置tensorRT生成engine
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
MySQL practice 45 lecture [row lock]
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
Idea format code idea set shortcut key format code
docker安装及启动mysql服务
Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
[AI practice] Application xgboost Xgbregressor builds air quality prediction model (I)
shardingsphere动态数据源
npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
Lvgl usage experience
403 error displayed when vs cloning