javascript - document.getElementById("") = "" 在 Laravel 刀片中不起作用
问题描述
我正在寻找一种在表单中设置“价值”的方法,我试过这个,但它不起作用。我应该如何解决它?
错误说
未捕获的 ReferenceError:setData 未在 HTMLInputElement.onclick 中定义
但是 setDate() 肯定存在....
<script>
function setData() {
document.getElementById("year").value = "2022";
}
</script>
<div>
<form method="GET" action={{ route('test')}}>
{{ Form::select('month', $date, 0 ) }}
<input type="button" id="b1" value="BUTTON1" onclick="setData()">
</form>
</div>
<form method="post" action={{ route('output')}}>
@csrf
<div class="col-md-6">
<input type="text" id="year" name="year" value ="2021">
<input type="text" name="month" value ="7"> <input type="text" name="day" value ="1">
</div>
</form>
解决方案
试试下面的脚本,
在您的第二个表单中添加名称
<form method="GET" action="{{ route('test')}}">
<select name="" id="month">
<option value="">Select</option>
<option value="jan">Jan</option>
<option value="feb">Feb</option>
</select>
<input type="button" id="b1" value="BUTTON1" onclick="setData()">
</form>
<form method="post" id="form2" action="{{ route('output')}}">
@csrf
<div class="col-md-6">
<input type="text" id="year" name="year" value ="2021">
<input type="text" name="month" value ="7"> <input type="text" name="day" value ="1">
</div>
</form>
<script>
var secondForm = document.getElementById('form2');
function setData() {
secondForm.year.value = '2022';
}
</script>
推荐阅读
- r - 循环遍历变量列表 - 嵌入式循环
- python - 如何在 Python BaseHTTPRequestHandler 中处理分块编码?
- python - 为什么系统杀死了我的 python 程序?但是我在 var/log 目录中没有找到任何日志
- routing - 无法匹配 clojurescript bidi 中的任意路由
- java - 在互联网连接等待循环之前显示吐司
- javascript - 应用程序可在 Android 和 IOS 模拟器中运行,但在发布后无法运行
- php - PHP对某个索引相同的多维数组值求和
- c++ - C++ 将对象转换为其原始类型
- android - android中的可排序tableview
- django - Django:search_device_list() 缺少 1 个必需的位置参数:'id'