簡體   English   中英

facebook風格的jquery tokeninput腳本在jquery-ui模態窗口中保留值

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

嘗試使用Facebook風格的tokeninput腳本,該腳本將以與FB使用的相同方式使用(使用jquery-ui獲取模式窗口),以將消息發送給社交網絡系統中的朋友。

單擊“打開對話框”按鈕(“ opener” ID使模式窗口出現)

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片段是:

<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-->

我可以從腳本中獲取標記化。 但是,如果我單擊“ opener” ID進行了一次標記,則在模式窗口中會保留其先前的標記,這顯然是我不希望的。

如何擺脫它?

看來您要兩次加載jquery.tokeninput.js文件-只要它在jQuery之后,就不需要在$(document).ready(...)中使用它。

顯示模態后(稱為$dialog.dialog('open'); ),嘗試調用:

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

這應該清除所有先前的標記,然后您可以在此之后添加任何想要的默認標記。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM