Empty or remove html tags

A. Add and delete labels

New mosaic html tags:

    AddGroupId:function(){
var groupId=$('#groupId2').val().trim();
var groupName=$('#groupId2').find('option:selected').text();
var v_content = "<p class='groupA'><span groupId=\""+groupId+"\" groupName=\""+groupName+"\">"+groupName+" </span>"+
"<a href=\"javaScript:void(0);\" onclick='groupAdd.deleteGroupId(this)'>删除 </a></p>";
$("#groupIdList1").append(v_content);
//$("#selected").append(v_content);
},

点击删除按钮,删除新增的html标签:

deleteGroupId:function(obj){
$(obj).parent().remove();
},

1. By obtaining the parent node label, and then deleted with the parent node includes the sub-node.

 

Second, other teammates found on the Internet written, clear and bulk delete method:

Original link: https: //blog.csdn.net/changqing5818/article/details/54313132/

Empty input box

$ ( "form: input") Returns all form objects form, including textarea, select, button, etc.
$ ( "form input") returns all the input tag objects form the
$ ( "form> input") to select all the specified " form "of elements specified in the" input "of direct child elements

form input belongs to level selector (returns after each of the selector matching element combined together)
form: INPUT belongs sheet selectors (Match all <input>, <textarea>, <select>, <button> element)


Clear operation:

$('input', form).each(function(){
var type = this.type;
var tag = this.tagName.toLowerCase();
if(tag == 'text' || tag == 'password' || tag == 'textarea') {
this.value = '';
} else if (type == 'checkbox' || type == 'radio') {
this.checked = false;
} else if (type == 'select') {
this.selectedIndex = -1;
}
});

To delete a span
Method 1: According id

removeSpan function () {
var obj = document.getElementById ( "SPAN1");
var parent = obj.parentNode;
parent.removeChild (obj); // + where the parent node by node object to be deleted to remove

// Here is the span delete your own, true representation even child nodes are also deleted together, in this case it is childspan, but false words of their own child and multi-node does not delete
//obj.removeNode(true);
// Also, if using a jquery, could write: $ (obj) .remove ();
}

 

Method 2: traversing form

$('span', form).each(function(){
    $(this).remove(); });

Guess you like

Origin www.cnblogs.com/xuhk1819/p/12190896.html