时间:2019-04-02 22:30:17

标签: css knockout.js

我有一个文本区域,我想通过敲除css / attr绑定和hasFocus绑定来消除焦点上的轮廓发光。但是轮廓光并未重新聚焦。  预先谢谢你。

var viewModel = {
  isFocus: ko.observable(false),
  outlineglow: ko.observable()
};

viewModel.isFocus.subscribe(function(focus) {
  if (focus) {
    viewModel.outlineglow("none");
  }
});

ko.applyBindings(viewModel);
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<textarea data-bind="hasFocus: isFocus, attr: { 'focus:outline': outlineglow }"> </textarea>

1 个答案:

答案 0 :(得分:1)

您可以使用style绑定根据可观察的SELECT contacts.id, fname, lname, email, address,uid,uniqud, group_concat(distinct pnumber order by pnumber),cid FROM contacts LEFT JOIN numbers ON contacts.uniqid = numbers.cid group by contacts.id, fname, lname, email, address,uid,uniqud,cid 来设置outline

isFocus
var viewModel = {
  isFocus: ko.observable(true)
};

ko.applyBindings(viewModel);

如果要集中使用许多<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> <textarea data-bind="hasFocus: isFocus, style: { outline: isFocus() ? 'none' : '1px dashed red'}"> </textarea>,可以使用css绑定来绑定style

class
var viewModel = {
  isFocus: ko.observable(true)
};

ko.applyBindings(viewModel);
.focused {
  outline-width: 1px;
  outline-style: dashed;
  outline-color: red;
  border-radius: 2rem;
}