当前位置:网站首页>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控制台输出。
边栏推荐
- 将时间戳转为指定格式的时间
- Use of El tree search method
- 【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
- Vs 2019 configure tensorrt to generate engine
- Open Visual Studio 2010 hangs when opening a SQL file sql file
- 简易版 微信小程序开发之for指令、上传图片及展示效果优化
- Limit of one question per day
- MongoDB复制集【主从复制】
- 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
- 简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
猜你喜欢

MongoDB复制集【主从复制】
![Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence](/img/60/bae0e8d92a53bcd2b2de3fb22b3b99.jpg)
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence

Unity3d RPG implementation (medium)
![MySQL practice 45 lecture [transaction isolation]](/img/a5/5420651d6be51e892976f02be8c43c.png)
MySQL practice 45 lecture [transaction isolation]

MongoDB安装 & 部署

VS 2019 配置tensorRT生成engine

Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop

Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11

VS code配置虚拟环境

Limit of one question per day
随机推荐
Spark on yarn resource optimization ideas notes
[combinatorics] basic counting principle (addition principle | multiplication principle)
Réglez la hauteur et lancez le système. Currenttimemillis catton
MongoDB安装 & 部署
The idea setting code is in UTF-8 idea Properties configuration file Chinese garbled
[pyg] understand the messagepassing process, GCN demo details
The series of hyperbolic function in daily problem
[leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
Table structure of Navicat export database
Compare float with 0
Summary of determinant knowledge points in Chapter 1 of Linear Algebra (Jeff's self perception)
为什么线程崩溃不会导致 JVM 崩溃
@Accessors注解作用指定前缀遵守驼峰命名
float与0比较
Solve high and send system Currenttimemillis Caton
Captura下载安装及在Captura配置FFmpeg
VS 2019 配置tensorRT生成engine
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
Pytorch轻量级可视化工具wandb(local)
The difference between static web pages and dynamic web pages & the difference between Web1.0 and Web2.0 & the difference between get and post