本帖最后由 zc19851108 于 2014-12-30 13:44 编辑
多次ctrl + f5 刷新,画红圈处会重复出现。
我的解决办法是
在 static/js/common.js 的
function simulateSelect(selectId, widthvalue) {
var selectObj = $(selectId);
if(!selectObj) return;
if(BROWSER.other) {
if(selectObj.getAttribute('change')) {
selectObj.onchange = function () {eval(selectObj.getAttribute('change'));}
}
return;
}
var widthvalue = widthvalue ? widthvalue : 70;
var defaultopt = selectObj.options[0] ? selectObj.options[0].innerHTML : '';
var defaultv = '';
var menuObj = document.createElement('div');
var ul = document.createElement('ul');
var handleKeyDown = function(e) {
e = BROWSER.ie ? event : e;
if(e.keyCode == 40 || e.keyCode == 38) doane(e);
};
var selectwidth = (selectObj.getAttribute('width', i) ? selectObj.getAttribute('width', i) : widthvalue) + 'px';
var tabindex = selectObj.getAttribute('tabindex', i) ? selectObj.getAttribute('tabindex', i) : 1;
for(var i = 0; i < selectObj.options.length; i++) {
var li = document.createElement('li');
li.innerHTML = selectObj.options.innerHTML;
li.k_id = i;
li.k_value = selectObj.options.value;
if(selectObj.options.selected) {
defaultopt = selectObj.options.innerHTML;
defaultv = selectObj.options.value;
li.className = 'current';
selectObj.setAttribute('selecti', i);
}
li.onclick = function() {
if($(selectId + '_ctrl').innerHTML != this.innerHTML) {
var lis = menuObj.getElementsByTagName('li');
lis[$(selectId).getAttribute('selecti')].className = '';
this.className = 'current';
$(selectId + '_ctrl').innerHTML = this.innerHTML;
$(selectId).setAttribute('selecti', this.k_id);
$(selectId).options.length = 0;
$(selectId).options[0] = new Option('', this.k_value);
eval(selectObj.getAttribute('change'));
}
hideMenu(menuObj.id);
return false;
};
ul.appendChild(li);
}
selectObj.options.length = 0;
selectObj.options[0]= new Option('', defaultv);
selectObj.style.display = 'none';
selectObj.outerHTML += '<a href="javascript:;" id="' + selectId + '_ctrl" style="width:' + selectwidth + '" tabindex="' + tabindex + '">' + defaultopt + '</a>';
//修改处
if($(selectId + '_ctrl_menu')){
$(selectId + '_ctrl_menu').innerHTML='';
}
menuObj.id = selectId + '_ctrl_menu';
menuObj.className = 'sltm';
menuObj.style.display = 'none';
menuObj.style.width = selectwidth;
menuObj.appendChild(ul);
$('append_parent').appendChild(menuObj);
$(selectId + '_ctrl').onclick = function(e) {
$(selectId + '_ctrl_menu').style.width = selectwidth;
showMenu({'ctrlid' selectId == 'loginfield' ? 'account' : selectId + '_ctrl'),'menuid':selectId + '_ctrl_menu','evt':'click','pos':'43'});
doane(e);
};
$(selectId + '_ctrl').onfocus = menuObj.onfocus = function() {
_attachEvent(document.body, 'keydown', handleKeyDown);
};
$(selectId + '_ctrl').onblur = menuObj.onblur = function() {
_detachEvent(document.body, 'keydown', handleKeyDown);
};
$(selectId + '_ctrl').onkeyup = function(e) {
e = e ? e : window.event;
value = e.keyCode;
if(value == 40 || value == 38) {
if(menuObj.style.display == 'none') {
$(selectId + '_ctrl').onclick();
} else {
lis = menuObj.getElementsByTagName('li');
selecti = selectObj.getAttribute('selecti');
lis[selecti].className = '';
if(value == 40) {
selecti = parseInt(selecti) + 1;
} else if(value == 38) {
selecti = parseInt(selecti) - 1;
}
if(selecti < 0) {
selecti = lis.length - 1
} else if(selecti > lis.length - 1) {
selecti = 0;
}
lis[selecti].className = 'current';
selectObj.setAttribute('selecti', selecti);
lis[selecti].parentNode.scrollTop = lis[selecti].offsetTop;
}
} else if(value == 13) {
var lis = menuObj.getElementsByTagName('li');
lis[selectObj.getAttribute('selecti')].onclick();
} else if(value == 27) {
hideMenu(menuObj.id);
}
};
}
|