当前位置:网站首页>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 - max. of array cases

d3.js&nvd3. JS - how to set the y-axis range - d3 js & nvd3. js — How to set y-axis range

Docker installing MySQL local remote connection docker container MySQL

Buffer Overflow Vulnerability Lab

Buuctf web (III)

Guidance process and service control

MySQL parsing serialized fields

How app inventor accesses resource files in assets directory

A solution to create a new EXCEL workbook on win10 computer and change the suffix to xlsm (normally it should be xlsx)
![【Pycharm踩坑记录】配置远程运行后提示,[Errno 2] No such file or directory](/img/71/92c06496a9d982294cac61595e0392.png)
【Pycharm踩坑记录】配置远程运行后提示,[Errno 2] No such file or directory
随机推荐
天猫商品详情接口,天猫商品优惠券接口,天猫api接口,天猫价格监控接口,天猫比价接口,品牌维权接口,天猫销量api接口,接口代码可对接数据分析业务,品牌维权,比价业务,行业分析业务接口代码分享
H5 mobile terminal adaptation
Deploy Yum warehouse and NFS shared services
Batch package and download Alibaba OSS files
Three methods to make the scroll bar of div automatically scroll to the bottom
Taobao commodity sales interface / Taobao commodity sales monitoring interface / cumulative commodity sales interface
useRoutes() may be used only in the context of a <Router> component.
ADT Google browser plug-in ad Terminator
3、 JS notes
GBase 8a磁盘问题及处理
Mongodb test case
8、 JS data type conversion
0.一些自己初学Solidworks的疑惑
How to save the video of wechat video number locally?
logstash配置参考文章
5、 Constant, variable
Implement authentication code login and remember password (cookie)
Vs installation of vassistx plug-in causes Chinese input of wpf-xaml file to be garbled. Solution
redis. exceptions. ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.
情绪处理技巧