简体   繁体   English

Javascript this.value onchange 不工作

[英]Javascript this.value onchange not working

I'm trying to get the value of a form input usign JS:我正在尝试获取表单输入 usign JS 的值:

HTML: HTML:

<td onchange="validate_hours(this)">{{ form.monday }}</td>

JS:记者:

function validate_hours(elem) {
   console.log(elem.value)
}

But I receive "undefined".但我收到“未定义”。

The {{ form.monday }} is a Django form {{ form.monday }} 是一个 Django 表格

Django form: Django表格:

<input type="number" name="form-0-monday" value="4.0" step="any" placeholder="0.0" id="id_form-0-monday">

I found a solution, I used firstChild to get the input and now is returning the value:我找到了解决方案,我使用 firstChild 获取输入,现在返回值:

JS JS

function validate_hours(elem) {
  input = elem.firstChild.value
  console.log(input)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM