Pass single value within onClick (without using a form submit)

前端 未结 2 1286
谎友^
谎友^ 2021-01-29 08:51

Rather than creating several putPriority fetches, I\'d ideally just like to pass a singular value.

But this value won\'t be entered via the user (ie not an input field)<

2条回答
  •  -上瘾入骨i
    2021-01-29 08:52

    you can use this to get current value :

    putPriority: function(e) {
     e.preventDefault();
     var currentStatus = e.currentTarget.getAttribute("value");
     return fetch(DATA_API, {
     method: 'PUT',
     body: JSON.stringify({
         status: currentStatus,
         tag: [
           {}
          ]
      })
      })
      .then(function(res){ return res.json(); })
      .then(function(data){ alert( JSON.stringify( data ) ) })
    },
    

    this will solve your problem

    var currentStatus = e.currentTarget.getAttribute("value");
    

提交回复
热议问题