gpt4 book ai didi

javascript - 收到错误 Uncaught TypeError : Cannot set property 'value' of null

转载 作者:行者123 更新时间:2023-11-28 02:21:33 24 4
gpt4 key购买 nike

我收到此错误Uncaught TypeError: Cannot set property 'value' of null, on ->

我的 html 是从函数 goSubmit() 传递值,

<form class="form-inline" id="formdaily" action="http://localhost:8080/reports/storewisedaily" method="POST">
<div class="box">
<div class="box-header">
<h3 class="box-title">Total Paid Orders - Report Data</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="datatables" class="table table-bordered table-striped">
<thead>
<tr>
<th>Month - Year</th>
<th>Amount</th>
</tr>
</thead>
<tbody>

<tr>
<td><a id="month_year" data-id="2019-01" onclick="goSubmit('2019-01')" href="#">2019-01</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-02" onclick="goSubmit('2019-02')" href="#">2019-02</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-03" onclick="goSubmit('2019-03')" href="#">2019-03</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-04" onclick="goSubmit('2019-04')" href="#">2019-04</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-05" onclick="goSubmit('2019-05')" href="#">2019-05</a></td>
<td>11,471.50</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-06" onclick="goSubmit('2019-06')" href="#">2019-06</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-07" onclick="goSubmit('2019-07')" href="#">2019-07</a></td>
<td>12.50</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-08" onclick="goSubmit('2019-08')" href="#">2019-08</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-09" onclick="goSubmit('2019-09')" href="#">2019-09</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-10" onclick="goSubmit('2019-10')" href="#">2019-10</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-11" onclick="goSubmit('2019-11')" href="#">2019-11</a></td>
<td>0.00</td>
</tr>
<tr>
<td><a id="month_year" data-id="2019-12" onclick="goSubmit('2019-12')" href="#">2019-12</a></td>
<td>0.00</td>
</tr>
<input type="hidden" id="select_month" name="select_month" value="">
<input type="hidden" id="select_store" name="select_store" value="3">
</tbody>
<tfoot align="right">
<tr><th></th><th></th></tr>
</tfoot>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</form>

在函数中,我想将 goSubmit() 的值传递给名为“select_month”的隐藏输入

  document.getElementById('select_month').value = m;

即使我对值进行硬编码,它似乎也没有通过。有人可以帮我周五和周六吗

<input type="hidden" id="select_month" name="select_month" value="">

function goSubmit(month_year) {
alert(month_year); // it pass value '2019-05'
var m = month_year.toString();
console.log(m);
alert(m);
//alert($('#select_month').val(m));
document.getElementById('select_month').value = m;
//alert(document.getElementById("select_month").value);
//alert($('#select_month').val(month_year));
//$("#select_store").val(3);
document.getElementById('select_store').value = 3;
document.getElementById('formdaily').submit();
}

最佳答案

Value 是存在于输入标签上的属性,所以请尝试一下。document.getElementById("select_month").value = m

关于javascript - 收到错误 Uncaught TypeError : Cannot set property 'value' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57319866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com