简体   繁体   English

使用jQuery拖放/文本编辑

[英]Drag and Drop / text editing with Jquery

I have to ask a question about jquery. 我不得不问一个关于jquery的问题。 I am new to jquery and found some code to drag and drop a text. 我是jquery新手,发现了一些拖放文本的代码。 i want to input a text in text box get its value and then drag and drop the text written. 我想在文本框中输入文本以获取其值,然后拖放所写的文本。

 <script type="text/javascript"> $("button:#Get").click(function () { $('#msg').html($('input:text').val()); }); $("button:#Reset").click(function () { $('#msg').html(""); $('input:text').val(""); }); $("button:#Set").click(function () { $('input:text').val("ABC"); $('#msg').html($('input:text').val()); }); $(function() { $( "#msg" ).draggable(); $( "#droppable" ).droppable({ drop: function( event, ui ) { $( this ) .addClass( "ui-state-highlight" ) .find( "p" ) .html( "Dropped!" ); } }); }); </script> 
 <div style="padding:16px;"> TextBox : <input type="text" value="Type something"></input> </div> <button id="Get">Get TextBox Value</button> <button id="Set">Set To "ABC"</button> <button id="Reset">Reset It</button> <div id="msg" class="ui-widget-content"> <p></p> </div> 

The problem is that these two scripts works in separate files perfectly. 问题在于这两个脚本可以完美地在单独的文件中工作。 But i have to merge it in a single file. 但是我必须将其合并到一个文件中。 Please help 请帮忙

Try this. 尝试这个。 Made changes to your selectors. 对选择器进行了更改。 If you wish to hide 1st draggable after the drop, just uncomment $("#msg").hide() 如果您希望在放置之后隐藏第一个可拖动对象,只需取消注释$("#msg").hide()

<div style="padding:16px;">
    TextBox : <input type="text" value="Type something"></input>
</div>

<button id="Get">Get TextBox Value</button> 
<button id="Set">Set To "ABC"</button> 
<button id="Reset">Reset It</button>


<div id="msg" class="ui-widget-content" style="border: 1px solid">
  <p></p>
</div>
<br>
    <br>
<div id="droppable" class="ui-widget-content" style="border: 1px solid">
  <p>Drag and drop here</p>
</div>

$("#Get").click(function () {   
    $('#msg').html($('input:text').val());
});

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

    $('#msg').html("");
    $('input:text').val("");

    });

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

    $('input:text').val("ABC");
    $('#msg').html($('input:text').val());

    });


    $( "#msg" ).draggable();
    $( "#droppable").droppable({
      drop: function( event, ui ) {
        var $text = $("#msg").text();
        $( this ).addClass( "ui-state-highlight" ).find( "p" ).html($text);
       // $("#msg").hide();
      }
    });

http://jsfiddle.net/7ck1m7q1/3/ http://jsfiddle.net/7ck1m7q1/3/

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

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