删除附加数据-jQuery [英] deleting the appended data - jquery

查看:108
本文介绍了删除附加数据-jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select: function (event, ui) {

        var staffItem = new Object();


        staffItem.StaffId = ui.item.id;
        staffItem.Name = ui.item.name;
        staffItem.Photo = ui.item.image;
        staffItem.Email=ui.item.email;
        staffItem.Mobile=ui.item.mobile;          

              var data = "<div><table width='100%'><tr><td align='right' ><div class='close16'/></td></tr></table><div><table><tr><td rowspan='4' width='50px;'><img src='" + staffItem.Photo + "' Width='48' Height='48'  /></td><td>" + staffItem.Name + " ( " + staffItem.StaffId + " )</td></tr><tr><td><table cellpadding='0' cellspacing='0'><tr><td>" + staffItem.Email + "</td><td>&nbsp;|&nbsp;</td><td>" + staffItem.Mobile + "</td></tr></table></td></tr></table></td></tr></table></div></div> ";
                $('#staffInCharge').css('background-color','#FFAA55');
                $('#staffInCharge').append(data);

am使用此代码将人员详细信息附加到div中,并且在close16类中使用图像文件(用于使用十字标记删除数据),如果单击十字标记,应删除附加数据我这样做了,而且当我追加新数据时(在现有数据的下方)一个接一个地追加时,我需要将其追加到右侧,该怎么做.

am using this code to append staff details into a div, and in the close16 class am using a image file(for cross mark to delete the data), if I click the cross mark the appended data should be deleted, how can I do that, and also when I append the new data its appending one by one(below of existing data) i need to append it to the right side, how can I do this.

推荐答案

要删除数据,您可以执行以下操作:

For deleting the data, you could do something like this:

$(document).on('click', '.close16', function() {
    $(this).parentsUntil('div').remove();
});

对于追加数据,这取决于您的DOM的外观以及您想要实现的目标.您可能想看看 insertAfter

As for appending data, it depends a bit on what your DOM looks like, and exactly what you want to achieve. You might want to have a look at insertAfter and insertBefore for controlling exactly where your data is added. Making things appear "to the right side" may be more a question of the styles of the elements you're inserting, than where in the DOM you're inserting them.

.append将内容添加到容器的底部,直到考虑您的标记.这是否与实际出现在容器中以前项目下方的项目相同,取决​​于这些元素的属性.

.append adds content to the bottom of a container as far as your markup is considered. Whether or not this is the same thing as items physically appear below previous items in the container depends on the properties of these elements.

如果要在另一个DIV后面添加一个DIV,则默认情况下它将显示在前一个DIV之下,但这更多与元素的显示模式有关,而不是其在代码中的位置. 示例.

If you're adding a DIV after another DIV, then it will, by default, appear below the former, but this has more to do with the element's display-mode than with its position in your code. Example.

如果DIV元素具有不同的显示模式,例如inline-block,则它们将显示在前一个元素的右侧. 示例.请注意,JavaScript不变.

If the DIV elements were of a different display mode, for instance inline-block, they would appear to the right of the previous element. Example. Note that the JavaScript doesn't change.

但是,如果您想用float: left;放置DIV,则可能会发现要插入的元素不是在容器底部,而是在clear: both元素之前,该元素始终位于底端.然后,您将必须使用类似insertBefore的名称. 示例.

However, if you instead wanted to position your DIVs with float: left;, you might find that you wanted to insert the elements not at the bottom of the container, but before a clear: both-element, that would always be at the bottom. You would then have to use something like insertBefore. Example.

哪种精确方法最适合您,取决于标记和样式的很多方面.说您想要右边"的东西并不能为我们提供足够的信息来帮助您.

Which exact approach works best for you depends on very many aspects of your markup and styles. Saying that you want something "to the right side" does not provide us with enough information to assist you in this regard.

这篇关于删除附加数据-jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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