单击HTML选择的父级

时间:2018-01-30 21:38:43

标签: javascript jquery html

禁用时,我似乎无法点击select的父级。我尝试允许用户通过点击来解锁输入,但它仅适用于inputs



    let $input = $('input')
    $input.parent().click(function() {
      $input.prop('disabled', false);
    })
    let $select = $('select')
    $select.parent().click(function() {
      $select.prop('disabled', false);
    })

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="parent">
      <input name="name" disabled placeholder="click me">
    </div>
    <div class="parent">
      <select name="thing" disabled>
        <option value="1">1</option>
      </select>
    </div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:5)

添加此样式:

Variable

这将导致禁用选择忽略鼠标,这允许其父级捕获点击。

<强>段:

&#13;
&#13;
getTasks(taskId: string): void {
  this.taskService.getTasks(taskId).subscribe(data => {
        this.tasks = data;
    },
    err => {
        //handle errors here
    });
}
&#13;
select[disabled] {
  pointer-events: none;
}
&#13;
let $input = $('input');
$input.parent().click(function() {
  $input.prop('disabled', false);
});

let $select = $('select');
$select.parent().click(function() {
  $select.prop('disabled', false);
});
&#13;
&#13;
&#13;