简体   繁体   English

facebook风格的jquery tokeninput脚本在jquery-ui模态窗口中保留值

[英]facebook style jquery tokeninput script retains value in the jquery-ui modal window

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. 尝试使用Facebook风格的tokeninput脚本,该脚本将以与FB使用的相同方式使用(使用jquery-ui获取模式窗口),以将消息发送给社交网络系统中的朋友。

Clicking on the 'open the dialog' button ('opener' id makes the modal window appear) 单击“打开对话框”按钮(“ opener” ID使模式窗口出现)

javascript snippet: javascript代码段:

    <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 snippet is : 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-->

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. 但是,如果我单击“ opener” ID进行了一次标记,则在模式窗口中会保留其先前的标记,这显然是我不希望的。

How to get rid of it? 如何摆脱它?

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. 看来您要两次加载jquery.tokeninput.js文件-只要它在jQuery之后,就不需要在$(document).ready(...)中使用它。

Once you've displayed your modal (called $dialog.dialog('open'); ) try, calling: 显示模态后(称为$dialog.dialog('open'); ),尝试调用:

$('#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. 这应该清除所有先前的标记,然后您可以在此之后添加任何想要的默认标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM