获取LI数据ID's来自动态内容
Get LI Data ID's from Dynamic Content
我试图获得最接近的UL元素,然后是LI数据id,但按钮什么也没做,没有错误,这表明它找不到元素。
这样做的目的是,用户输入当天可用的货车数量,然后在每辆货车下拖放每次送货。然后,用户将点击创建投递单,它将只打印指定货车中这些物品的PDF。
现在我只需要创建dropsheet来提醒数据id,这样我就可以将它们传递给AJAX。
$(function() {
$('#vans').on('input', function() {
vansDo();
doMap();
});
function vansDo() {
var vans = $('#vans').val();
var drops = $("#placeVans").html('<br /><p class="text-center">Drag each booking onto the required vehicle. Move each booking into delivery position. Then print off drop sheets for each vehicle.</p>');
if (vans >= '1') {
for (i = 1; i <= vans; i++) {
drops = $("#placeVans").html();
$("#placeVans").html(drops + '<div id="van' + i + '" class="col-lg-4"><h3 class="align-center"><i class="fa fa-truck"></i> Van ' + i + '</h3><ul id="sortable2" class="droptrue c-white bg-gray"></ul><a data-toggle="modal" data-id="' + i + '" data-target="#modal-map" class="btn btn-primary m-t-10 m-r-10"><i class="fa fa-map-marker"></i> View Map</a><a class="dropsheet btn btn-primary m-t-10"><i class="fa fa-file-pdf-o"></i> Create Dropsheet</a></div>');
};
} else {
$("#placeVans").html(drops_default);
}
sortinit();
$("#sortable1").html(cache).sortable("refresh");
$("#sortable2").disableSelection();
}
$('#placeVans').on('click', '.dropsheet', function() {
$(this).closest('ul').find('li').each(function() {
alert($(this).data('id'));
});
});
});
<ul id="sortable1" class="droptrue">
<li data-id="1" class="sortable col-md-12 m-b-10 p-t-10 p-b-10 bd-3 bg-opacity-20 fade in">1</li>
<li data-id="2" class="sortable col-md-12 m-b-10 p-t-10 p-b-10 bd-3 bg-opacity-20 fade in">2</li>
<li data-id="3" class="sortable col-md-12 m-b-10 p-t-10 p-b-10 bd-3 bg-opacity-20 fade in">3</li>
<li data-id="4" class="sortable col-md-12 m-b-10 p-t-10 p-b-10 bd-3 bg-opacity-20 fade in">4</li>
</ul>
<div id="placeVans" class="row m-b-20"></div>
所以我需要以下部分来工作,LI从sortable1拖到sortable2。
$('#placeVans').on('click', '.dropsheet', function() {
$(this).closest('ul').find('li').each(function() {
alert($(this).data('id'));
});
});
您的a
元素,即:按钮不在ul
标记内。所以你的$(this).closest('ul')
不会工作。但是ul
与a
标记封装在同一个父标记下,所以您可以执行此操作。
$('#placeVans').on('click', '.dropsheet', function() {
$(this).parent().find('ul.droptrue').find('li').each(function() {
alert($(this).data('id'));
});
});
变化在该部分CCD_ 6中。
也从你的代码中提取。$("#placeVans").html(.....
您的ul
中没有li
标签。此处<ul id="sortable2" class="droptrue c-white bg-gray"></ul>
不确定这是否是故意的。只是指出。
ul
不是button
的祖先,而是兄弟,因此
$('#placeVans').on('click', '.dropsheet', function() {
//$(this).closest('div').find('ul li').each(function() {})
$(this).siblings('ul').find('li').each(function() {
alert($(this).data('id'))
})
});
相关文章:
- 如何在没有ajax的情况下将javascript动态数据发送到php变量
- 从要使用Protractor测试的服务器异步加载的动态数据列表的列表
- 不适用于动态数据的Angular指令来自$http
- 如何在字符串中的值之前删除字符串中的动态数据?/ 使用 Lodash 的 _.trimStart 与动态数据
- 剑道数据源,将动态数据发送到服务器
- 无限滚动,动态数据按上次修改状态排序
- 如何在高图表中设置动态数据
- 使用Select2和Meteor.js进行动态数据采集
- 谷歌图表与动态数据和分页是可能的
- 使用AngularJs在自定义TinyMCE编辑器中添加动态数据
- 如何为jQuery帖子输入动态数据参数
- 将不同的符号添加到具有动态数据的高图表中
- Aurelia@儿童动态数据
- 从动态数据生成AngularJS UI模板
- 我可以将初始动态数据从基于RESTful api的服务器端传递到基于角度的前端页面吗
- d3.js带有标签的动态数据
- 将sessionStorage(JSON)中的动态数据附加到Listview中
- 如何使用Javascript在html源中添加动态数据
- 试图在网站上抓取谷歌地图api生成的动态数据,但正常抓取返回空白
- 从angularjs中的$scope在$http.post中发送动态数据