使用具有一个HTML ID的javascript .on和.editableselect

我有一个选择输入,我要选择使其同时可编辑并使用 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>
yhgfhgfhgfgfhgfh 回答:使用具有一个HTML ID的javascript .on和.editableselect

据我所知,可编辑选择事件监听与默认监听不同。为了收听更改事件,您应该在以下示例中进行操作。

    $(document).ready(function () {
        $("#stock_name").on('select.editable-select',function (event,element) {
            var stock_name = element.val();
            $.ajax({
                url: '/sales-price/getunitsellingprice/'+stock_name,method: 'GET',success: function (response) {
                    console.log(response);
                    $("#unit_selling_price").val(response);
                },});
        });
    });
本文链接:https://www.f2er.com/3119227.html

大家都在问