简体   繁体   English

如何在Jade中获得动态生成的输入的值

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

Hello I am trying to get the value of dynamically generated input and then tie that to an onclick event handler that retrieves the value. 您好,我正在尝试获取动态生成的输入的值,然后将其绑定到检索该值的onclick事件处理程序。 I can't think of a way on how to do it. 我想不出一种方法。 Here is the code: 这是代码:

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

Here is where the value of the dynamically generated input needs to go 这是需要动态生成的输入值的位置

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")

The value of the dynamically generated input can go into the input value of start time or end time. 动态生成的输入的值可以输入开始时间或结束时间的输入值。 It doesn't matter 没关系

So I found the simplest way to do this is to have an event listener that triggers a function which passes the Id that is dynamically generated as a parameter. 因此,我发现最简单的方法是让事件侦听器触发一个函数,该函数传递作为参数动态生成的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

Where the value needs to go 价值何去何从

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")

script function 脚本功能

    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