可排序和可丢弃Jquery不断替换wordpress中的数据
Sortable and Droppable Jquery keeps on replacing data in wordpress
我正在尝试将HTML表单中的数据排序到div中。每次拖动新项目时,它都会替换上一个项目,而不是从顶部或底部排序。我不认为这与wordpress有任何关系。只是我正在wordpress中开发它。我做错了什么或错过了什么?下面是代码。
脚本
$(function () {
$("#blocks").droppable({
drop: function (event, ui) {
var id = ui.draggable.attr('id');
layout = $.ajax({type:"GET",url:'wp-content/themes/dynamictheme/templates/' + id + '.html',async:false}).responseText;
$("#blocks").wrap( layout );
}
}).sortable({
revert: true
});
$(".draggable").draggable({
helper: "clone"
});
});
html
<div class="sortable" >
<ul id="blocks" class="ui-sortable empty" ></ul>
</div>
<div id="slideout">
<div id="slideMenu">
<ul style="list-style-type: none;">
<li id="template1" class="draggable">
<img src="wp-content/themes/dynamictheme/img/template/template1.png" width="200"/>
</li>
<li id="template2" class="draggable">
<img src="wp-content/themes/dynamictheme/img/template/template2.png" width="200"/>
</li>
</ul>
</div>
</div>
模板html
<section class="success" id="template1" >
<div class="container" style="width:auto;">
<div class="row">
<div class="col-lg-12 text-center">
<h2>About</h2>
<hr class="star-light">
</div>
</div>
<div class="row">
<div class="col-lg-4 col-lg-offset-2">
<p>Freelancer is a free bootstrap theme created by Start Bootstrap. The download includes the complete source files including HTML, CSS, and JavaScript as well as optional LESS stylesheets for easy customization.</p>
</div>
<div class="col-lg-4">
<p>Whether you're a student looking to showcase your work, a professional looking to attract clients, or a graphic artist looking to share your projects, this template is the perfect starting point!</p>
</div>
<div class="col-lg-8 col-lg-offset-2 text-center">
<a href="#" class="btn btn-lg btn-outline">
<i class="fa fa-download">Download Theme</i>
</a>
</div>
</div>
</div>
</section>
如果没有将数据作为列表项删除,请将列表元素中的布局变量附加到#blocks-ul-
$("#blocks").droppable({
drop: function (event, ui) {
var id = ui.draggable.attr('id');
layout = $.ajax({type:"GET",url:'wp-content/themes/dynamictheme/templates/' + id + '.html',async:false}).responseText;
$("#blocks").append('<li>' + layout + '</li>');
}
使用两个可排序列表,而不是可拖动和可丢弃列表,然后使用以下代码:
$(function() {
$("#list2").sortable({
connectWith:'.connect',
stop: function (event, ui) {
var id = ui.item.sortable.attr('id');
ui.item.html($.ajax({type:"GET",url:'wp-content/themes/dynamictheme/templates/' + id + '.html',async:false}).responseText);
}
$("#blocks").sortable({
connectWith:'.connect'
});
});
相关文章:
- 无法从 jQuery RSS Feed 中的 localStorage 动态替换类
- 我如何找到一个句子中的所有空格并替换忽略它们
- 如何用更合适的内容替换document.write
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 在wordpress一定时间后更改自定义字段
- 在DOM中查找一个模式并替换它's的内容使用jquery
- 用空格替换下划线PHP
- str.split(someString).join(someOtherString)是否等效于替换
- 使用javascript的图像替换循环
- 如何使MailHandler.php在Wordpress中工作
- window.location替换并传递URL历史记录条目中的变量
- Wordpress插件根据需要加载js和css
- 无法再创建Wordpress页面
- Wordpress:替换源(域名)链接
- 在向下滚动JS/HTML/CSS wordpress网站时替换徽标图像
- 将导航替换为wordpress中的引导程序导航栏
- jQuery搜索和替换不起作用(Wordpress)
- 可排序和可丢弃Jquery不断替换wordpress中的数据
- 在Wordpress中查找和替换Iframe URL
- 如何使用jquery使wordpress帖子循环并替换HTML输出