Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如果未找到搜索文本,则向用户显示错误_Jquery_Jstree - Fatal编程技术网

Jquery 如果未找到搜索文本,则向用户显示错误

Jquery 如果未找到搜索文本,则向用户显示错误,jquery,jstree,Jquery,Jstree,我有一个jquery脚本,它绑定到jstree并搜索该树,如果找到,则突出显示三个节点。这很有效。但是如果没有找到搜索测试,我喜欢向用户发出警告。你知道我该怎么做吗 Javascript: <script type="text/javascript"> function myFunction() { $(document).ready(function(){ var value=document.getElementById("search_fie

我有一个jquery脚本,它绑定到jstree并搜索该树,如果找到,则突出显示三个节点。这很有效。但是如果没有找到搜索测试,我喜欢向用户发出警告。你知道我该怎么做吗

Javascript:

<script type="text/javascript"> 
    function myFunction()
    {
    $(document).ready(function(){

    var value=document.getElementById("search_field").value; 

        $("#search_tree").click(function () { 

            $("#tree").jstree("search",value);

    });

     document.getElementById("search_field").value='';
     }); 
    }

函数myFunction()
{
$(文档).ready(函数(){
var value=document.getElementById(“搜索字段”).value;
$(“#搜索树”)。单击(函数(){
$(“#树”).jstree(“搜索”,值);
});
document.getElementById(“搜索字段”)。值=“”;
}); 
}

html:


搜寻

您可以从下面的代码中获得想法。如果您需要任何进一步的帮助,请提供正在工作的JSFIDLE示例,我将修改代码以与您的代码一起工作

$("div#jstree").bind("search.jstree", function (e, data) {
    //document.getElementById("results").innerHTML="Found " + data.rslt.nodes.length + " nodes matching '" + data.rslt.str + "'.";
   if (data.rslt.nodes.length == 0){
    alert("No search results found");
   }
});

由于某些原因,我无法创建JSFIDLE。我的原始代码在帖子里。我试过这样的方法:$(“#tree”).jstree(“search”,value)。函数(e,data){if(data.rslt.nodes.length==0){alert(“找不到搜索结果”);}给我一个错误,想知道如何解决这个问题吗?从jsTree 3.0.0-beta8开始,这是:if(data.res.length==0)
$("div#jstree").bind("search.jstree", function (e, data) {
    //document.getElementById("results").innerHTML="Found " + data.rslt.nodes.length + " nodes matching '" + data.rslt.str + "'.";
   if (data.rslt.nodes.length == 0){
    alert("No search results found");
   }
});