【问题标题】:Why does toggle inside modal won't work in laravel?为什么在模式内部切换在 laravel 中不起作用?
【发布时间】:2022-01-03 14:50:35
【问题描述】:

您好,我目前正在处理模式内的切换(活动 - 非活动)。 我能够使其工作,将活动变为非活动。但是,将其恢复为活动将不起作用,并且状态保持为非活动状态。

我怎样才能做到这一点?这里缺少什么?

提前致谢

图片 html

这是我的 JS

$("#updatetaxform").on('submit', function (e) {
e.preventDefault() 
const pid = $("#updatetaxform [name=pid]").val();
const IsActive = $("#updatetaxform").prop('checked') == true ? 1 : 0;
$.ajax({
    data: {
        pid,
        IsActive
    },
    url: "/edit-tax",
    type: "POST",
    success: function (data) {
        console.log(data.success) 
        var oTable = $('#tax-info-table').dataTable()
        oTable.fnDraw(false)
        Swal({
            type: 'success',
            title: 'Success!',
            text: "Successfully updated!",
            showConfirmButton: false,
            timer: 3000
        }).then(function () {
            location.reload()
        })
       
    },
    error: function (data) {
        console.log('Error:', data.responseJSON.message);
        Swal({
            type: 'error',
            title: 'Tax Information Error',
            text: data.responseJSON.message
        })
    }
}) })

这是我的输入 html

<div class="form-group">
        <label for="">Active Status</label>
        <input type="checkbox" data-toggle="toggle" data-onstyle="success" data-offstyle="danger" data-style="ios slow" data-width="100" data-height="20" name="IsActive" {{ $taxstatus->IsActive ? 'checked' : ''}}>
      </div>

这是我的控制器

public function editTax(Request $request)
{
$tax = TaxDetails::where('id', $request->id)->update(
            ['pid' => $request->pid, 'IsActive' => $request->IsActive ]
            );}

public function index()
{
  $tax1 = TaxDetails::where('pid', Session::get('pid'))->first();
  return view('pages.tax-information', [
        'taxstatus' => $tax1
        
    ]);
}

【问题讨论】:

    标签: javascript laravel laravel-5


    【解决方案1】:

    我发现我的错误,我没有从刀片文件中获取 ID 甚至元素。 所以这是我的修复,我添加了 ID 并在我的 JS 中使用它。

    从此:

    const IsActive = $("#updatetaxform").prop('checked') == true ? 1 : 0;
    

    到这里:

    var IsActive = $("#IsActive").prop('checked') == true ? 1:0;
    

    这个也可以

    var IsActive = $("input:checkbox").is("checked") ? 1:0;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 2023-01-16
      相关资源
      最近更新 更多