jquery-ui - 动态添加 jquery 可排序元素后,拖动并调整元素大小并获取 jquery 中的位置
问题描述
我已经成功添加了动态元素,但它是可排序的,我希望添加的动态元素应该是可拖动和可调整大小的。
我已经从这里复制了工作演示。我只想保存用户将添加的添加元素的顶部、左侧、高度和宽度像素值。我尝试了几种方法,但这对我没有帮助。
/* didn't worked */
$(".new_element_class").draggable({
cursor: "move",
drag : function(event, ui){
$('#for_drag').html('Dragging Element! left : ' + Math.floor(ui.position.left) + 'Top : ' + Math.floor(ui.position.top));
}
});
$('.new_element_class').resizable({
handles : "n,s,w,e,ne,se,sw,nw",
// maxHeight : 90,
// maxWidth : 215,
minWidth : 215,
minHeight : 30,
helper: "ui-resizable-helper",
animate: true,
start : function(event, ui){
$('#for_resize').html('Resizeing Element! Width : ' + Math.floor(ui.size.width) + ' Height : ' + Math.floor(ui.size.height));
},
stop : function(event, ui){
$('#for_resize').html('Resizeing Element! Width : ' + Math.floor(ui.size.width) + ' Height : ' + Math.floor(ui.size.height));
},
resize : function(event, ui){
$('#for_resize').html('Resizeing Element! Width : ' + Math.floor(ui.size.width) + ' Height : ' + Math.floor(ui.size.height));
},
});
/* didn't worked */
此外,我想为选择框、单选按钮和复选框动态添加更多选项,其中包含动态内容,如values 和 innerHTML。我只尝试了选择框输入字段的jquery 和 javascript方法,但它添加了第一个元素,
例如:如果我添加了两个选择框输入并且我想为第二个选择框添加更多选项,它正在为第一个添加。
我试过这个 Jquery 代码
var select_id = "#select_name_"+rand_no;
var option_id = "#option_adder"+rand_no;
$(select_id).live('click', function(){
name = $(this).text();
if($("#" + name).length == 0) {
$(option_id).click(function(){
$(select_id)
.find('option')
.end()
.append('<option value="whatever">text</option>')
.val('whatever');
});
} else {
alert('this record already exists');
}
});
我也试过这个 Javascript 代码
var select_id = "select_name_"+rand_no; // for javascript
var option_id = "option_adder"+rand_no; // for javascript
var min1 = 0,
min2 = 0,
max = 100,
select_id_obj = document.getElementById(select_id),
option_id_obj = document.getElementById(option_id);
function dataadder(id){
if(id == option_id_obj){
min1++;
var opt = document.createElement('option');
alert(opt);
opt.value = 'data is '+min1;
opt.innerHTML = 'data is '+min1;
select_id_obj.appendChild(opt);
}
}
这是我的小提琴代码。
有人可以帮我弄这个吗??
解决方案
推荐阅读
- javascript - 将活动类添加到选定元素的角度(可能是多个活动元素)
- android - react-native-firebase 实现在现有项目中是不可能的( react-native@.54 )。gradle 构建失败
- javascript - Ajax on select input click: Fill options from Ajax response
- php - 通过参数数组php获取数据
- node.js - Node Js、Git、Heroku:Git 提交不推送到 git,因为大文件在过去提交了几次提交
- ios - IOS/Objective-C:以编程方式在按钮下的中心线
- apache-spark - 集群中作业运行时的火花流错误(纱线资源管理器)
- security - 使用 Jenkins Google 登录插件时的自定义用户
- javascript - 翻转大部分 svg 图像,但不翻转其中的文本
- xml - Spring restTemplate.exchange 在服务器端抛出 XML parsererror