var pattern=/^[+,-]?\d+$/;
iptValue=ipt.value.trim();
if(!pattern.test(iptValue)){
alert("请确认输入的是数字?");
return;
}
if(!city.match(/^[A-Za-z\u4E00-\u9FA5]+$/)){
alert("城市名必须为中英文字符!")
;
}
//绑定事件函数
function on(element,eventName,listener){
if (element.addEventListener){
element.addEventListener(eventName,listener,false);
}
else (element.attachEvent){
element.attachEvent('on'+eventName,listener);
}
else
element['on'+eventName]=listener;
}
on(mybt,'click',addBtnHandle);
获取事件对象和事件的目标
var EventUtil={
getEvent:(event){
return event ? event:window.event;
},getTarget:return event.target||event.srcElement;
}
}
event=EventUtil.getEvent(event);
var target=EventUtil.getTarget(event);
var tt;
switch(target.id){//
case "l-input":
(validate()){
t.unshift(ipt.value);
}
break;
case "r-input" (validate()){
t.push(ipt.value);
}
break;
event=EventUtil.getTarget(event);
if (target.tagName.toLowerCase() === 'span') {记得要转化为小写;
numUl.removeChild(target);
var tt=target.dataset.num;如何获取自定义元素的值;
removeData(tt);
alert("移除"+target.innerHTML);innerHTML也可以用来读;
}
第二段代码
event=var tt=target.parentNode.dataset.num;父节点的获取
tt=parseInt(tt);
if (target.parentNode.tagName.toLowerCase() === 'span') {
numUl.removeChild(target.parentNode);
alert("移除"+removeData(tt));
}
for(var i=0;i<length-1;i++){
var j=0;j<length-i-1;j++){
if (t[j]>t[j+1]){
tem=t[j];
t[j]=t[j+1];
t[j+1]=tem;
}
}
}
var newSpan = document.createElement('span'var newSpanText = document.createElement('div');
newSpan.style.position = 'relative';
newSpanText.innerHTML = numbers[i];
newSpanText.style.position = 'absolute';
newSpanText.style.bottom = '-1.5em';
newSpan.style.width = '20px';
newSpan.style.height = numbers[i] + 'px';
newSpan.appendChild(newSpanText);
switch (method) {
case 'leftIn':
result.insertBefore(newSpan,spans[0]);
;
case 'rightIn':
result.appendChild(newSpan);
;
}