使用jquery拖放表单输入。标签如何修复后 [英] Drag and drop form-inputs using jquery. How label is fixed after

查看:74
本文介绍了使用jquery拖放表单输入。标签如何修复后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建动态表单控件。



其中文本框,单选按钮可以拖放形式。





我在这里发现拖放。



[ ^ ]



及以下链接到我需要的但是在这里需要拖放

http://jsfiddle.net/techbrij/uNNMr/



我尝试过:



@ {

ViewBag.Title =draganddrop3;

布局= null;

}



< h2> draganddrop3< / h2>

< !doctype html>

< html lang =en>

< head>

< meta charset =utf- 8>

< meta name =viewportcontent =width = device-width,initial-scale = 1>

< title> jQuery UI Droppable - 默认功能< / title>

< link rel =stylesheethref =// code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css\">

< link rel =stylesheet href =/ resources / demos / style.css>

< style>

#box {

宽度:100px;

身高:100px;

填充:0.5em;

浮动:左;

保证金:10px 10px 10px 0 ;

}



.draggable {

float:left;

z -index:99;

}



#droppable {

宽度:300px;

身高:500px;

填充:0.5em;

职位:绝对;

剩余:33%;

top:15%;

保证金:10px;

}

< / style>

< script src =https://code.jquery.com/jquery-1.12.4.js >< / script>

< script src =https://code.jquery.com/ui/1.12.1/jquery-ui.js>< / script> ;

< script>

$(function(){

$(。draggable)。draggable();

$(#droppable)。droppable({



drop:function(event,ui){

debugger ;

var draggableId = ui.draggable.attr(id);

//每次getfileldId获取文本框(我如何获得当前可拖动的id值)

if(ui.draggable.attr(id)==textbox){

$(this).append('< input id =Text1type =text/>')

}

else if(ui.draggable.attr(id)==chekbox){

$(this).append('< input id =Checkbox1type =checkbox/>')

}

else if(ui.draggable.attr(id)==dropdown){

$(this).append('< select name = dropdown>'+

'< option value =volvo> Volvo< / option>'+

'< option value =saab > Saab< / option>'+

'< option value =fiat>菲亚特< / option>'+

'< option value = audi>奥迪< /选项>'+

'< / select>')



}



}

});

});

< / script>

< / head>

< body>



< div id =class =>

< ul class =draggableid =textbox> Textbox< />< / ul>< br />

< ul类= draggableid =chekbox> chekbox< /> < / ul>< br />

< ul class =draggableid =dropdown> dropdown< />< / ul>< br />





< / div>



< div id = droppableclass =ui-widget-header>

< p>放在这里< / p>

< / div>





< / body>

< / html>

I want to create dynamic form controls.

where textbox, radio button can drag and drop in form.


I found drag and drop at here.

[^]

and below link exactly what I required but at here required drag and drop
http://jsfiddle.net/techbrij/uNNMr/

What I have tried:

@{
ViewBag.Title = "draganddrop3";
Layout = null;
}

<h2>draganddrop3</h2>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Droppable - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#box {
width: 100px;
height: 100px;
padding: 0.5em;
float: left;
margin: 10px 10px 10px 0;
}

.draggable {
float: left;
z-index: 99;
}

#droppable {
width: 300px;
height: 500px;
padding: 0.5em;
position: absolute;
left: 33%;
top: 15%;
margin: 10px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(function () {
$(".draggable").draggable();
$("#droppable").droppable({

drop: function (event, ui) {
debugger;
var draggableId = ui.draggable.attr("id");
//every time getfileldId get textbox (how can i get currend draggable id value)
if (ui.draggable.attr("id") == "textbox") {
$(this).append('<input id="Text1" type="text" />')
}
else if (ui.draggable.attr("id") == "chekbox") {
$(this).append('<input id="Checkbox1" type="checkbox" />')
}
else if (ui.draggable.attr("id") == "dropdown") {
$(this).append('<select name="dropdown">' +
'<option value="volvo">Volvo</option>' +
'<option value="saab">Saab</option>' +
'<option value="fiat">Fiat</option>' +
' <option value="audi">Audi</option>' +
' </select>')

}

}
});
});
</script>
</head>
<body>

<div id="" class="">
<ul class="draggable" id="textbox">Textbox</></ul><br />
<ul class="draggable" id="chekbox">chekbox</> </ul><br />
<ul class="draggable" id="dropdown">dropdown</></ul><br />


</div>

<div id="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>


</body>
</html>

推荐答案

(function(){
(function () {


(。draggable)。draggable();
(".draggable").draggable();


(#droppable)。droppable({



drop:function(event,ui){

debugger;

var draggableId = ui.draggable.attr(id);

//每次getfileldId获取文本框(我如何获得当前可拖动的id值)

if(ui.draggable.attr(id)==textbox){
("#droppable").droppable({

drop: function (event, ui) {
debugger;
var draggableId = ui.draggable.attr("id");
//every time getfileldId get textbox (how can i get currend draggable id value)
if (ui.draggable.attr("id") == "textbox") {


这篇关于使用jquery拖放表单输入。标签如何修复后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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