一、insertBefore
function validObj(objName){
var obj=document.getElementsByName(objName);
if(obj[0].ismust=='1'){
if(obj[0].value==''){
var parent=obj[0].parentNode;
var element=document.createElement('span');
element.innerHTML='testvalidate';
parent.insertBefore(element,obj[0]);alert();
}
}
}
二、insertAfter
该方法利用insertbefore间接实现
function insertAfter(newElement,targetElement) {
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement) {
parent.appendChild(newElement);
} else {
parent.insertBefore(newElement,targetElement.nextSibling);
}
}
欢迎加入我的QQ交流群425783133