facebook样式jquery tokeninput脚本在jquery-ui模式窗口中保留值 [英] facebook style jquery tokeninput script retains value in the jquery-ui modal window

查看:90
本文介绍了facebook样式jquery tokeninput脚本在jquery-ui模式窗口中保留值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用facebook风格的令牌输入脚本,我将以与FB使用相同的方式使用该脚本(使用 jquery-ui 获取模态窗口)向社交网络系统中的朋友发送消息。

trying to use facebook style tokeninput script which I'll use in the same way as FB uses(using jquery-ui to get the modal window) to send messages to friends in a social networking system.

点击打开对话框按钮(开启者ID会显示模态窗口)

Clicking on the 'open the dialog' button ('opener' id makes the modal window appear)

javascript片段:

javascript snippet:

    <script type="text/javascript">
    $(document).ready(function() {
        $("input[type=button]").click(function () {
            alert("Would submit: " + $(this).siblings("input[type=text]").val());
        });
    });

</script>

    <script type="text/javascript">

    $(document).ready(function() {



             $(".show_dialog script").remove();
         $dialog = $('.show_dialog');


         $dialog.dialog({
                width:500,
                height:300,
                autoOpen: false,
                title: 'Basic Dialog'
            });

        $('#opener').click(function() {
            $dialog.dialog('open');

            $(this).siblings("input[type=text]").val('this is a value ')// ADDED BY ME 


            //$("#demo-input-facebook-theme", $dialog).val('');





            $(".border_text", $dialog).css("border","1px solid red");
            // prevent the default action, e.g., following a link
            return false;
        });
    });
    </script>

html代码段是:

<button id="opener">Open the dialog</button>


<div class="show_dialog" style="display:block ;">


               <label class="send_meg_recipient_txt">To:</label>







<h2 id="theme">Facebook Theme</h2>
    <div>
        <input type="text" id="demo-input-facebook-theme" name="blah2" " /><br></br>
        <input type="button" value="Submit" />


        <script type="text/javascript">
        var script = jQuery('<script/>').attr('src', 'js/jquery.tokeninput.js').appendTo('head');

        $(document).ready(function() {


        var script = jQuery('<script/>').attr('src', 'js/jquery.tokeninput.js').appendTo('head');


        var q_string=$("#demo-input-facebook-theme").val();





            $("#demo-input-facebook-theme",$dialog).tokenInput("token_find/my3.php?q=q_string", {

                preventDuplicates: true,
                theme:"facebook"

            });


        /*
        */  

        });


        </script>


    </div>


 </div><!--end of class  show_dialog-->

我可以从脚本中获取标记。
但是如果我点击开启者ID后再进行一次标记化,则会出现模态窗口,其前一个标记保留在原位,这显然是我不想要的。

I can get the tokenizing from the script. But after tokenizing for once if i click on the 'opener' id, the modal window appears with its previous tokens retained in place, which I obviously don't want.

如何摆脱它?

推荐答案

看来您正在加载 jquery.tokeninput.js 文件两次 - 你不应该在 $(文件).ready(...)中需要它,只要它来自jQuery。

It appears that you're loading the jquery.tokeninput.js file twice - you shouldn't need it in $(document).ready(...) so long as it comes after jQuery.

一旦你显示你的模态(称为 $ dialog.dialog('open'); )尝试,调用:

Once you've displayed your modal (called $dialog.dialog('open');) try, calling:

$('#demo-input-facebook-theme')。tokenInput(clear);

这应该清除所有以前的代币,然后你可以添加你想要的任何默认代币。

That should clear all of the previous tokens, then you can add any default tokens you want after that.

这篇关于facebook样式jquery tokeninput脚本在jquery-ui模式窗口中保留值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆