我有一个选择输入,我要选择使其同时可编辑并使用 ajax请求更改JS函数。但是,由于我两次使用了select输入的id,因此只有一个功能起作用。对于与我的but the one I got相关的案例,我已经尝试过这样的方法了,但远远没有解决我的问题。它是Javascript,HTML / bootstrap问题,尽管我使用的是laravel。 这是代码: create.blade.php
<div class="form-group">
<label>Product Name</label>
<select name="stock_name" id="stock_name" class="form-control">
<option value="" hidden>Select Product Name</option>
@foreach ($stocks as $stock)
<option value="{{ $stock->stock_name }}">{{ $stock->stock_name}}</option>
@endforeach
</select>
</div>
同一文件中的JS部分
<script>
$('#stock_name').editableSelect({
effects: 'slide',duration: 600
});
</script>
<script>
$(document).ready(function () {
$("#stock_name").on('change',function () {
var stock_name = $(this).val();
$.ajax({
url: '/sales-price/getunitsellingprice/'+stock_name,method: 'GET',success: function (response) {
console.log(response);
$("#unit_selling_price").val(response);
},});
});
});
</script>