如何在 HTML 表单中添加 jstree 搜索插件

发布于 2024-12-20 18:52:34 字数 2060 浏览 5 评论 0原文

我的 jstree 搜索插件在 HTML 页面中运行良好。树的数据通过ajax加载,并且通过ajax执行搜索。

一切都工作正常,直到我把它变成另一种形式。

如果我将相同的代码放入 HTML 表单中,它将不再起作用,因为不会执行搜索。

未执行搜索,因为当我单击插件的搜索按钮时会提交整个表单。

如何捕获搜索按钮的点击并阻止提交整个表单?

全局表单有自己的提交按钮,并且仍然可以正常工作。

我尝试了此线程中的解决方案,但它不起作用: http://groups.google.com/group/jstree/browse_thread/thread/7945aa59fca2d9c9

这也不起作用:

<form id="list" name="list" action="save.php" method="post">

    <!-- jstree button and input text for search plugin -->
    <div id="mmenu">
        <input type="submit" id="search" value="Go" />
        <input type="text" id="text" value=""  />
    </div>

    <!-- the tree container -->
    <div id="indexation" class="indexation"></div>

    <input id="url" type="text" name="url" value="" size="30" title="www.example.org"/>

    <input type="submit" name="sendform" value="Save" />
</form>
<script type="text/javascript">
// Code for the menu buttons
     $(document).ready(function(){

    $("#mmenu input").click(function () {
        switch(this.id) {
            case "add_default":
            case "add_folder":
                $("#indexation").jstree("create", null, "last", {
            "attr" : {
            "rel" : this.id.toString().replace("add_", "") }
                });
                break;
            case "search":
                $("#indexation").jstree("search", document.getElementById("text").value);
                break;
            case "text": break;
            default:
                $("#indexation").jstree(this.id);
            break;
        }
    });
});
</script>

任何想法/提示将不胜感激

这是 jsfiddle

http://jsfiddle.net/v9VRr/6/

谢谢,

I have the jstree search plugin working fine inside a HTML page. The data for the tree is loaded with ajax, and the search is permformed with ajax.

Everything works fine until I put it in another form.

If I put the same code inside a HTML form it doesn't work anymore because the search is not performed.

The search is not performed because the whole form is submitted when I click the search button of the plugin.

How do I catch the click on the search button and prevent the whole form to be submitted ?

The global form has its own submit button and it still works fine.

I tried the solution in this thread but it doesn't work :
http://groups.google.com/group/jstree/browse_thread/thread/7945aa59fca2d9c9

Also this does not work :

<form id="list" name="list" action="save.php" method="post">

    <!-- jstree button and input text for search plugin -->
    <div id="mmenu">
        <input type="submit" id="search" value="Go" />
        <input type="text" id="text" value=""  />
    </div>

    <!-- the tree container -->
    <div id="indexation" class="indexation"></div>

    <input id="url" type="text" name="url" value="" size="30" title="www.example.org"/>

    <input type="submit" name="sendform" value="Save" />
</form>
<script type="text/javascript">
// Code for the menu buttons
     $(document).ready(function(){

    $("#mmenu input").click(function () {
        switch(this.id) {
            case "add_default":
            case "add_folder":
                $("#indexation").jstree("create", null, "last", {
            "attr" : {
            "rel" : this.id.toString().replace("add_", "") }
                });
                break;
            case "search":
                $("#indexation").jstree("search", document.getElementById("text").value);
                break;
            case "text": break;
            default:
                $("#indexation").jstree(this.id);
            break;
        }
    });
});
</script>

Any idea/tip would be greatly appreciated

Here is the jsfiddle :

http://jsfiddle.net/v9VRr/6/

thank you,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乄_柒ぐ汐 2024-12-27 18:52:34

我找到了一个解决方案,虽然不是很聪明,但至少有效。只需将搜索所需的 jstree html 放在表单元素之外:

<form id="list" name="list" action="save.php" method="post">

<!-- the tree container -->
<div id="indexation" class="indexation"></div>

<input id="url" type="text" name="url" value="" size="30" title="www.example.org"/>
<input type="submit" name="sendform" value="Save" />

<form>

<!-- jstree button and input text for search plugin -->
<div id="mmenu">
    <input type="submit" id="search" value="Go" />
    <input type="text" id="text" value=""  />
</div>

然后通过 CSS 将 div id="mmenu" 放置在您需要的位置。

I found a solution, not really clever but at least it works. Just put the jstree html needed for search outside of the form elements :

<form id="list" name="list" action="save.php" method="post">

<!-- the tree container -->
<div id="indexation" class="indexation"></div>

<input id="url" type="text" name="url" value="" size="30" title="www.example.org"/>
<input type="submit" name="sendform" value="Save" />

<form>

<!-- jstree button and input text for search plugin -->
<div id="mmenu">
    <input type="submit" id="search" value="Go" />
    <input type="text" id="text" value=""  />
</div>

Then position the div id="mmenu" where you need it via CSS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文