簡體   English   中英

如何在Jade中獲得動態生成的輸入的值

[英]How to get value of dynamically generated input in Jade

您好,我正在嘗試獲取動態生成的輸入的值,然后將其綁定到檢索該值的onclick事件處理程序。 我想不出一種方法。 這是代碼:

h2 Labels
    each labelName in label
        h4 #{(JSON.stringify(labelName)).substr(1).slice(41, -1).replace(/['"]+/g, '')}
        form(action='/labelform', method='post', id='labelForm')
            input(type='hidden', value='#{(JSON.stringify(labelName.slice(41, -1))}', id='#{(JSON.stringify(labelName.slice(41, -1))}')
        button(type="button" onclick='enterStartTime()') Start Time 
        button(type="button" onclick='enterEndTime()') End Time
        br

這是需要動態生成的輸入值的位置

label(for='startTime') start time
input(type='text', value=startTime, name='startTime', id='startTime', placeholder="00:01:00")
label(for='endTime') End Time
input(type='text', value=endTime, name='endTime', id='endTime', placeholder="00:02:15")

動態生成的輸入的值可以輸入開始時間或結束時間的輸入值。 沒關系

因此,我發現最簡單的方法是讓事件偵聽器觸發一個函數,該函數傳遞作為參數動態生成的ID。

h2 Labels
    each labelName in label
        h4 #{(JSON.stringify(labelName)).substr(1).slice(41, -1).replace(/['"]+/g, '')}
        form(action='/labelform', method='post', id='labelForm')
            input(type='hidden', onchange='addValue(#{(JSON.stringify(labelName.slice(41, -1))})', value='#{(JSON.stringify(labelName.slice(41, -1))}', id='#{(JSON.stringify(labelName.slice(41, -1))}')
        button(type="button" onclick='enterStartTime()') Start Time 
        button(type="button" onclick='enterEndTime()') End Time
        br

價值何去何從

label(for='startTime') start time
input(type='text', value=startTime, name='startTime', id='startTime', placeholder="00:01:00")
label(for='endTime') End Time
input(type='text', value=endTime, name='endTime', id='endTime', placeholder="00:02:15")

腳本功能

    function addValue(labelName){
      document.getElementById('startTime').value = document.getElementById('labelName').value
}

暫無
暫無

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

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