这是我的下拉列表和自动编号格式
如果有人选择NK / W将获得No.Reg:
001 / NK / W / 2018,002 / NK / W / 2018,003 / NK / W / 2018
如果有人选择NK / S将获得No. Reg 001 / NK / S / 2018。
如果年份发生变化,自动编号将再次重置为001
答案 0 :(得分:0)
此处的解决方案更多地与javascript相比,而不是Laravel或PHP。
检查出来
https://jsfiddle.net/j6znavy9/
<p>
Reg No: Auto/
<select id="mySelect">
<option selected disabled>Select an Option</option>
<option value="NK/W">NK/W</option>
<option value="NK/S">NK/S</option>
<option value="MM/A">MM/A</option>
</select>
Year: *
<select id="yearSelect">
<option selected disabled>Select a Year</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</p>
<script>
$(document).ready(function() {
function pad(number, size) {
var s = String(number);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
var year, mySelect, auto = 1;
$('#yearSelect').on('change', function(){
year = $(this).val();
auto = 1;
});
$('#mySelect').on('change', function(){
if( year === null || year === undefined ) {
alert('year is not defined!');
} else {
alert('Reg No: ' + pad(auto, 3) + '/' + $(this).val() + '/' + year);
auto++;
}
})
});
</script>