如何在 blade 中获取输入值
how to get input value in blade
我正在尝试获取 Blade 中先前输入的值。
<input name="people" type="number" cols="5">
@for($i=1; $i<$people; $i++)
<input type="text" cols="50">
@endfor
根据第一个输入的数值,我想在同一个 Blade 文档中生成输入字段。
但是显示的技巧是错误的,我得到一个错误 "Undefined variable: people"。有可能这样做吗?
我正在使用 Laravel 5.2.
不依赖于blade。您可以在任何地方使用下面的代码。
<head>
<title>Test</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
</head>
<body>
<div style="margin: 20px 10px;">
<input name="people" id="people" type="number" value="2" cols="5">
<script type="text/javascript">
$('#people').change(function(){
$('#inputs').html('');
for (var i = 0; i < $('#people').val(); i++) {
$('#inputs').append('<input type="text" name="input_'+$('#people').val()+'" value="'+$('#people').val()+'"><br>');
}
});
</script>
</div>
<div id="inputs"></div>
</body>
</html>
我正在尝试获取 Blade 中先前输入的值。
<input name="people" type="number" cols="5">
@for($i=1; $i<$people; $i++)
<input type="text" cols="50">
@endfor
根据第一个输入的数值,我想在同一个 Blade 文档中生成输入字段。 但是显示的技巧是错误的,我得到一个错误 "Undefined variable: people"。有可能这样做吗? 我正在使用 Laravel 5.2.
不依赖于blade。您可以在任何地方使用下面的代码。
<head>
<title>Test</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
</head>
<body>
<div style="margin: 20px 10px;">
<input name="people" id="people" type="number" value="2" cols="5">
<script type="text/javascript">
$('#people').change(function(){
$('#inputs').html('');
for (var i = 0; i < $('#people').val(); i++) {
$('#inputs').append('<input type="text" name="input_'+$('#people').val()+'" value="'+$('#people').val()+'"><br>');
}
});
</script>
</div>
<div id="inputs"></div>
</body>
</html>