当前位置:网站首页>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>
原网站

版权声明
本文为[fengyehongWorld]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270537517424.html