簡體   English   中英

輸入選項的值

[英]Value for Input Options

需要有關如何獲取輸入選項值的幫助:

<div class="input-group mb-3">
        <div class="input-group-prepend">
          <label class="input-group-text" for="inputGroupSelect01">Color</label>
        </div>
        <select class="custom-select" id="inputGroupSelect01">
          <option selected>Choose...</option>
          <option value="1" >Blue</option>
          <option value="2">Green</option>
          <option value="3">Yellow</option>
          <option value="4">Orange</option>
          <option value="5">Red</option>
        </select>
      </div>

My model is like this:

        User.register({
            fname: req.body.firstname,
            lname: req.body.lastname,
            nickname: req.body.nickname,
            email: req.body.email,
            color: req.body.value,
            designation: req.body.designation,
            username: req.body.username,

我無法獲得所選選項的價值,感謝您的幫助。 謝謝你。

要在前端和后端之間進行通信,您必須設置路由並發出 HTTP 請求。 我建議使用Axios

要獲得輸入值,您可以執行以下操作:

const inputValue = document.getElementById('inputGroupSelect01').value;

然后用 Axios:

async sendInputValue() {
    const url = 'http://localhost:5000/'

    await Axios.post(`${url}register`, inputValue)
        .then(res => {
            // Do whatever on success
        }).catch(err => {
            // Do whatever with error
        }
}

然后,在您的后端:

router.post('register', (req, res) => {
   // Use it however you want
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM