Jquery mobile jQuery移动搜索输入清除,带Knockout hasFocus绑定

Jquery mobile jQuery移动搜索输入清除,带Knockout hasFocus绑定,jquery-mobile,knockout.js,Jquery Mobile,Knockout.js,我很难让jQuery移动搜索输入文本“clear text button”与Knockout的hasFocus绑定一起工作 我的目标是当用户搜索时,屏幕上的其他内容消失。但是,当用户不搜索时,其他内容是可见的。一切正常,除了 当我输入jQuery移动搜索输入并单击“X”清除输入时,搜索输入会失去焦点,但输入不会被清除。应该发生的情况正好相反(搜索输入应该被清除,搜索输入应该保持焦点) 来证明我在说什么 HTML <div id="wrapper"> <div data-

我很难让jQuery移动搜索输入文本“clear text button”与Knockout的hasFocus绑定一起工作

我的目标是当用户搜索时,屏幕上的其他内容消失。但是,当用户不搜索时,其他内容是可见的。一切正常,除了

当我输入jQuery移动搜索输入并单击“X”清除输入时,搜索输入会失去焦点,但输入不会被清除。应该发生的情况正好相反(搜索输入应该被清除,搜索输入应该保持焦点)

来证明我在说什么

HTML

<div id="wrapper">
    <div data-role="content">
        <h3 data-bind="visible: !IsSearching()">I am some content</h3>
        <input type="search" data-bind="hasFocus: IsSearching" />
        <h3 data-bind="visible: !IsSearching()">I am some more content</h3>
    </div>    
</div>
<div id="wrapper">
    <div data-role="content">
        <h3 data-bind="visible: !IsSearching() && SearchText().length == 0">I am some content</h3>
        <input type="search" data-bind="value: SearchText, hasFocus: IsSearching" />
        <h3 data-bind="visible: !IsSearching() && SearchText().length == 0">I am some more content</h3>
    </div>    
</div>

我能够解决这个问题。我这样做的目的是,如果搜索文本没有聚焦,并且搜索文本长度为0,那么它只会隐藏页面上的其他元素

如果有人有类似的问题,是一个链接到工作小提琴

代码如下:

HTML

<div id="wrapper">
    <div data-role="content">
        <h3 data-bind="visible: !IsSearching()">I am some content</h3>
        <input type="search" data-bind="hasFocus: IsSearching" />
        <h3 data-bind="visible: !IsSearching()">I am some more content</h3>
    </div>    
</div>
<div id="wrapper">
    <div data-role="content">
        <h3 data-bind="visible: !IsSearching() && SearchText().length == 0">I am some content</h3>
        <input type="search" data-bind="value: SearchText, hasFocus: IsSearching" />
        <h3 data-bind="visible: !IsSearching() && SearchText().length == 0">I am some more content</h3>
    </div>    
</div>