该表格单元格包含两个输入-一个“编号设备”选择和一个“未编号设备”选择,并且根据前一个字段仅显示一个。这是那个单元格:
<td>
<div class="form-group" id="NumberedNameDiv">
<div class="col-md-12">
<select id="NumberedName" name="NumberedName" class="form-control select2_field">
<option value=""></option>
@foreach (App\Models\Equipment::all()->sortby('Name') as $row)
<option <?php if ("$row->id" == "$equip1name") { ?> selected="selected" <?php } ?> value="{{ $row->Name }}">{{ $row->Name }}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group" id="UnnumberedNameDiv">
<div class="col-md-12">
<select id="UnnumberedName" name="UnnumberedName" class="form-control select2_field">
<option value=""></option>
@foreach (App\Models\Equipmentrates::all()->sortby('EquipmentName') as $row)
<option <?php if ("$row->EquipmentName" == "$equip1name") { ?> selected="selected" <?php } ?> value="{{ $row->EquipmentName }}">{{ $row->EquipmentName }}</option>
@endforeach
</select>
</div>
</div>
</td>
该单元格可以正确显示,但是无论显示什么单元格,我的JavaScript都会始终选择NumberedName字段。这是JavaScript:
$("#equipment tr").each(function () {
var row = $(this).closest('tr');
var equiptype = row.find('input[name="EquipType"]:checked', '#EquipTypeSelector').val();
if(equiptype == 'Numbered')
{
document.getElementById('NumberedNameDiv').style.display ='block';
document.getElementById('UnnumberedNameDiv').style.display ='none';
equipment = row.find( 'td:eq(1) :selected' ).val();
$.ajax({
type: 'GET',
url: '/equiprates/getvalues',
data: {equipment : equipment},
success: function(data) {
daily = data.daily;
weekly = data.weekly;
monthly = data.monthly;
duration = row.find( 'td:eq(2) :selected' ).val();
row.find('input[id^="Quantity"]').val(1);
if (duration == 1 || duration == 2 || duration == 3)
{
revenue = daily * duration;
row.find('input[id^="EquipTotal"]').val(revenue);
}
if (duration == 4)
{
revenue = weekly;
row.find('input[id^="EquipTotal"]').val(revenue);
}
if (duration == 12)
{
revenue = monthly;
row.find('input[id^="EquipTotal"]').val(revenue);
}
}})
}
if(equiptype == 'Unnumbered')
{
document.getElementById('NumberedNameDiv').style.display ='none';
document.getElementById('UnnumberedNameDiv').style.display ='block';
equipment = row.find( 'td:eq(1) :selected' ).val();
quantity = row.find('input[id^="Quantity"]').val();
$.ajax({
type: 'GET',
url: '/equiprates/getrecord',
data: {ratename : equipment},
success: function(data) {
daily = data;
weekly = daily * 4;
monthly = weekly * 3;
duration = $( 'input[id^="Duration"] option:selected' ).val();
if (duration == 1 || duration == 2 || duration == 3)
{
revenue = daily * duration * quantity;
row.find('input[id^="EquipTotal"]').val(revenue);
}
if (duration == 4)
{
revenue = weekly * quantity;
row.find('input[id^="EquipTotal"]').val(revenue);
}
if (duration == 12)
{
revenue = monthly * quantity;
row.find('input[id^="EquipTotal"]').val(revenue);
}
}})
}
});
是否有更好的方法?本质上,当设备类型为Unnumbered时,我需要它从UnnumberedName中选择值。谢谢
答案 0 :(得分:0)
在下一节中使用else代替if。如果在我尝试使用另一种方法处理您的代码时
删除是否
const pkgVersion = require('./package.json').version;
const VERSION = {
'process.env': {
VUE_APP_VERSION: JSON.stringify(pkgVersion)
}
}
在此处插入其他
if(equiptype == 'Unnumbered'){
}