当前位置:网站首页>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控制台输出。
边栏推荐
- Hi3536c v100r001c02spc040 cross compiler installation
- [mathematical logic] predicate logic (individual word | individual domain | predicate | full name quantifier | existence quantifier | predicate formula | exercise)
- C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
- 基于QT的tensorRT加速的yolov5
- VS 2019配置tensorRT
- Converts a timestamp to a time in the specified format
- 小程序获取用户头像和昵称
- C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
- Node start server
- The idea cannot be loaded, and the market solution can be applied (pro test)
猜你喜欢

用Three.js做一個簡單的3D場景

Use three JS make a simple 3D scene

Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences

ffmpeg之 一张/多张图片合成视频

Hi3536c v100r001c02spc040 cross compiler installation

用Three.js做一个简单的3D场景

别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!

VS 2019 配置tensorRT生成engine

MongoDB安装 & 部署

numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
随机推荐
Nce detail of softmax approximation
MySQL MAC download and installation tutorial
shardingsphere动态数据源
QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
简易版 微信小程序开发之for指令、上传图片及展示效果优化
[embedded module] OLED display module
Introduction à mongodb
MongoDB簡介
Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop
Limit of one question per day
Some preliminary preparations for QQ applet development: make an appointment for a development account, download and install developer tools, and create QQ applet
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
PAT乙级常用函数用法总结
Téléchargement et installation du client Filezilla
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
Yolov5 project based on QT
[mathematical logic] normal form (conjunctive normal form | disjunctive normal form | major item | minor item | maximal item | minor item | principal conjunctive normal form | principal disjunctive no
C # webrequest post mode, based on "basic auth" password authentication mode, uploads files and submits other data using multipart / form data mode
Pytoch configuration
解决高并发下System.currentTimeMillis卡顿