自己写的select

由于项目中下拉框的list比较长 显的不好看,于是自己写了一个select 时间关系 写的不是很规范;都是使用的内嵌样式,可以自己调整select的高度

调用方式:只需要把 装有select的 父标签(如div,form,里面装有多个select)id传入 changeselect(id) 即可 [color=red]changeselect('divid')[/color]
代码:


var ly_select_currtren=null; //存放当前操作的下拉框
var ly_input_currtren=null; //存放当前操作的 input
function changeselect(id){
$('#'+id).find('select').each(function(i){
var csel = $(this);
var top = isExplorer(ExplorerType.MSIE)?'absmiddle':'top';
var inp = $('<input readonly id="'+id+i+'" type="text" />').prependTo(csel.parent());
var ini = $('<img align="'+top+'" style="cursor:pointer;" alt="" src="cnznjt_images/arrowxl.png" />');
inp.after(ini);
inp.width(csel.width()-17).val(csel.find('option:first').text());

if(csel[0].className.indexOf('validate') != -1)
inp.addClass('validate[custom[isnull]'); //这里是为了培训项目中的验证框架 要不要无所谓

csel.hide();
inp[0].onclick=hand;
ini[0].onclick=hand;
var options = csel.find('option');
var w = csel.width();
var h = 150;


function hand(event){
ly_select_currtren = csel;
ly_input_currtren = inp;

$('.selectdiv').remove();
var pos = GetObjPos(inp[0]);
var jid1 = $('<div id="id1" class="selectdiv" style="width:300px;height:98px;border:#7F9DB9 1px solid;z-index:202;position:absolute;background:#ffffff;overflow-y:scroll;"></div>').appendTo('body');
var str = '';
options.each(function(){ //获取原来select中的option 放到div中模拟select下拉列表
str += '<div myid="'+this.value+'" onclick="clickhand(this)" onmouseout="this.style.backgroundColor=\'\';this.style.color=\'\'" onmouseover="this.style.backgroundColor=\'blue\';this.style.color=\'white\'" style="overflow:hidden;white-space:nowrap;heigth:20px;cursor:pointer;width:'+(w-20)+'px;margin-top:1px;" title="'+$(this).text()+'">'+$(this).text()+'</div>';

});
jid1.css('left',pos.x).css('top',pos.y+22).width(w).height(h).html(str);
stopBubble(event);
document.onmousedown=function(){
jid1.remove();
      document.onmousedown=null; 
}
jid1[0].onmousedown=function(event){
//只阻止了向上冒泡,而没有阻止向下捕获,所以点击con的内部对象时,仍然可以执行这个函数
stopBubble(event);
}
return false;

}
function bb(d){
alert(d.className)
csel.val(d.className);
$('.selectdiv').remove();
}
});
}
function clickhand(d){
$('.selectdiv').remove();
ly_select_currtren.val(d.getAttribute('myid'));
ly_input_currtren.val(d.innerHTML);
ly_input_currtren[0].focus();
ly_input_currtren[0].blur();
if(ly_select_currtren[0].onchange)
ly_select_currtren[0].onchange();

}
function CPos(x, y){
this.x = x+1;
this.y = y;
}
function GetObjPos(ATarget){ //获取坐标
var target = ATarget;
var pos = new CPos(target.offsetLeft, target.offsetTop);

var target = target.offsetParent;
while (target)
{
pos.x += target.offsetLeft;
pos.y += target.offsetTop;

target = target.offsetParent
}

return pos;
}
function stopBubble(e){
if(e && e.stopPropagation){
e.stopPropagation(); //w3c
}else{
window.event.cancelBubble=true; //IE
}
}
在SQL中,使用SELECT语句自己造数有多种方式,以下为你详细介绍: ### 常数查询 可以使用SELECT语句选择字符串常数、数字常数以及日期常数进行造数。示例如下: ```sql SELECT '商品' AS string, 38 AS number, '2020-01-01' AS date; ``` 该示例中,通过SELECT语句创建了三个列,分别为`string`、`number`和`date`,并为它们赋予了相应的常数。这种方式简单直接,适用于需要临时生成固定数据的场景。 ### 对数字和日期进行算数运算造数 在SELECT中可以对数字和日期进行加减乘除等运算来生成新的数据。例如: ```sql SELECT u_score + 10 AS new_score_plus, u_score - 10 AS new_score_minus, u_score * 2 AS new_score_double, u_score / 2 AS new_score_half FROM T_USER; ``` 此示例中,对`T_USER`表中的`u_score`列进行了不同的算数运算,生成了新的列`new_score_plus`、`new_score_minus`、`new_score_double`和`new_score_half`,展示了如何通过运算来创造新的数据。 ### 使用VALUES子句 使用`VALUES`子句可以创建一个虚拟的表,其中包含自己定义的数据。示例如下: ```sql SELECT * FROM (VALUES (1, 'Apple'), (2, 'Banana'), (3, 'Cherry')) AS Fruits(id, name); ``` 在这个示例中,通过`VALUES`子句创建了一个名为`Fruits`的虚拟表,包含`id`和`name`两列,并插入了三行数据。这种方式可以方便地创建临时数据集。 ### 使用UNION ALL组合多个SELECT语句 可以使用`UNION ALL`将多个SELECT语句的结果组合在一起,从而自己造数。示例如下: ```sql SELECT 1 AS num, 'One' AS word UNION ALL SELECT 2, 'Two' UNION ALL SELECT 3, 'Three'; ``` 该示例通过`UNION ALL`将三个SELECT语句的结果合并成一个结果集,生成了包含数字和对应英文单词的表。 ### 使用系统函数生成序列 一些数据库系统提供了生成序列的函数,例如在PostgreSQL中可以使用`generate_series`函数。示例如下: ```sql SELECT generate_series(1, 10) AS num; ``` 此示例使用`generate_series`函数生成了从1到10的整数序列。 ### 使用CTE(公共表表达式) CTE可以用于创建临时的命名结果集,方便后续的查询。示例如下: ```sql WITH Numbers AS ( SELECT 1 AS num UNION ALL SELECT num + 1 FROM Numbers WHERE num < 10 ) SELECT * FROM Numbers; ``` 该示例使用CTE创建了一个名为`Numbers`的临时结果集,通过递归查询生成了从1到10的整数序列。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值