当前位置:网站首页>ES6 use of dynamic attributes
ES6 use of dynamic attributes
2022-06-13 08:47:00 【fengyehongWorld】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ES6 Dynamically create attributes in objects </title>
</head>
<body>
from Input box <input id="from" type="text" onchange="changeEvent(this)">
<br>
to Input box <input id="to" type="text" onchange="changeEvent(this)">
</body>
<script> /* DOM Elemental change event , from DOM Of this Of elements in the structure id And the input of value */ function changeEvent({
id, value = ''}) {
if(value.trim() == '') {
return; } const submitData = {
// According to the id, Dynamically create attributes in objects , And give the input value Value complement 6 position [id == 'from' ? 'fromAttribute' : 'toAttribute']: value.padStart(6, '0'), }; // According to the id Dynamically create access paths doAjax(`/testUrl/${
id == 'from' ? 'fromLink' : 'toLink' }`, submitData, function({
state, singleData}) {
if(state != "SUCCESS") {
return; } // according to id Dynamically structure the data from the objects returned from the back end $(`#${
id}`).val(singleData[id == 'from' ? 'fromName' : 'toName']); }) } </script>
</html>
边栏推荐
- JS - array de duplication in the array object case
- Uni app subcontracting loading and optimization
- WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]
- JS - for cycle case: Horse grain
- 容器概念和云原生
- Problèmes et traitement du disque gbase 8a
- JS - print 99 multiplication table of the for cycle case
- Buuctf web (VI)
- JS wrapper object
- On the use of visual studio
猜你喜欢
A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)
WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]
MySQL sorts according to the specified order of the specified fields
redis
Diversified tables through TL table row consolidation
Differences and uses among cookies, localstorage, sessionstorage, and application caching
redis
2020-12-28
Uni app essay
Svg text stroke effect
随机推荐
In order to resist the flood, the soldiers have been fighting for 89 hours. How many days and hours are there in total?
关于RSA加密解密原理
WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]
2021-04-16
DIY无人机(匿名拓控者P2+F330机架)
The 360 mobile assistant on Huawei maimang 7 cannot be uninstalled
Svg text stroke effect
Common network problems and troubleshooting methods of gbase
GBase 8a磁盘问题及处理
Docker installing MySQL local remote connection docker container MySQL
Filebeat collects logs to elk
A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)
Yarn package management tool
H5 mobile terminal adaptation
Implement authentication code login and remember password (cookie)
Deploy Yum warehouse and NFS shared services
centos 安装mysql及设置远程访问
Buuctf web (III)
Input prohibit copy and paste
Cesium displays a pop-up box at the specified position and moves with the map