1. 程式人生 > >js添加元素,和刪除當前元素

js添加元素,和刪除當前元素

eva for doc his con orm set lang ()

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-3.0.0.min.js"></script>
</head>
<body>
<div class="main">
	<div class="tag-mess-phone">
		<label for="createDateRange" class="control-label label-tag tag-mes-control-label">電話號碼</label>
		<input class="form-control" id=‘inputphoneValue2‘ onkeyup="value=value.replace(/[^\d]/g,‘‘)" placeholder="請輸入手機號" maxlength="11">
		<button class="btn margin-left" onclick="deletePhone(this)" type="button">刪除</button>
	</div>
	<div class="tag-mess-send-add">
		<button  onclick="addMessPhone()">添加</button>
	</div>
</div>
<script>
function addMessPhone(){
        var $params=‘‘;
            $params+=‘<div class="tag-mess-phone">‘ 
            $params+=‘<label for="createDateRange" class="control-label label-tag tag-mes-control-label">‘+"電話號碼"+‘</label>‘
            $params+=‘<input class="form-control" id="inputphoneValue2" placeholder="請輸入手機號" onkeyup="value=value.replace(/[^\d]/g,\‘\‘)"  maxlength="11">‘
            $params+=‘<button class="btn margin-left" onclick="deletePhone(this)" type="button">‘+"刪除"+‘</button>‘
            $params+=‘</div>‘
       $(".tag-mess-send-add").before($params);
 }      

function deletePhone(e){
	e.parentNode.parentNode.removeChild(e.parentNode);
}

</script>	
</body>
</html>

  

js添加元素,和刪除當前元素