【问题标题】:How to disable an input field if it has value in blade.php如果输入字段在blade.php中有值,如何禁用它
【发布时间】:2019-07-01 06:52:32
【问题描述】:

如果输入字段有值,我会尝试禁用它。不知何故,它看起来像这样:

<input type="text" name="sex" value="{{ old('sex', $user['sex']) }}" placeholder="">

我尝试添加类似:

<input type="text" name="sex" value="{{ old('sex', $user['sex']) }}" 
  disabled= {{ $user['sex'] == null ? disabled :'' }}  >

但它不起作用。顺便说一下,我正在使用blade.php。

【问题讨论】:

  • 你可以使用 javascript 或 jQuery 吗?
  • 如果可以,试试这个:$(documet).ready(function () { if ($(".yourInput").val() !== "") { $(". yourInput").setAttribute("disabled"); } }
  • @Hema_Elmasry 不幸的是我不能使用。不管怎么说,还是要谢谢你。 :)

标签: php laravel-blade disabled-input


【解决方案1】:

试试这个

  <input type="text" name="sex" value="{{ old('sex', $user['sex']) }}" {{ $user['sex'] ? '' : 'disabled' }}  >

【讨论】:

  • 谢谢。我刚刚添加了$user['sex'] == '' 以使其正常工作:)
【解决方案2】:

禁用该字段会破坏验证规则。我宁愿使用只读属性。

<input class="form-control" name="name" type="text" {{ $role->name ? 'readonly' : '' }} value="{{ old('name', $role->name) }}"  required="true" aria-required="true"/>

【讨论】:

    猜你喜欢
    • 2019-05-15
    • 1970-01-01
    • 2019-09-01
    • 2011-10-09
    • 2019-11-15
    • 1970-01-01
    • 2021-03-25
    • 2013-06-12
    • 2019-06-28
    相关资源
    最近更新 更多