随笔-8  评论-8  文章-10  trackbacks-0
javascript题
1.使用javascript创建一个矩形类
类中的属性:
名称 name
颜色 color
宽度 width
高度 height
提供完整的构造方法
提供一个计算面积的方法 getArea()
答案:
function Rectangle(name,color,width,height){
        
this.name = name;
        
this.color = color;
        
this.width = width;
        
this.height = height;
     
this.getArea = function(){
            
return this.width*this.height;
        }

    }

//测试代码
var t = new Rectangle('test','red',5,5);
alert(t.getArea());

注:矩形  rectangle
    三角形 triangle

2.解释with关键字的用法

with 语句 为一个或一组语句指定默认对象。

用法:with (<对象>) <语句>;

with 语句通常用来缩短特定情形下必须写的代码量。在下面的例子中,请注意 Math 的重复使用:

    x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10);
    y = Math.tan(14 * Math.E);

当使用 with 语句时,代码变得更短且更易读:

    with (Math) {
      x = cos(3 * PI) + sin(LN10);
      y = tan(14 * E);
    }
注:with语句是运行缓慢的代码段,尤其是在已设置了属性值时。大多数情况下如果可能,最好避免使用它。


3.使用javascript DOM模型 创建table  2行2列
a.写出新增和删除行方法
b.写出修改列内容的方法
c.对表格进行排序

答案:

var mytab = null;
 
function createTab(){
        mytab 
= document.createElement("table");
        mytab.border 
= "1px";
        document.body.appendChild(mytab);
        
var mytr = mytab.insertRow();
        
var mytd = mytr.insertCell();
        mytd.innerText
="c";
        mytd 
= mytr.insertCell();
        mytd.innerText
="b";

        mytr 
= mytab.insertRow();
        mytd 
= mytr.insertCell();
        mytd.innerText
="a";
        mytd 
= mytr.insertCell();
        mytd.innerText
="d";
        
        
//insertTR(1);
        //deleteTR(1);
        //updateCell(1,1,"xx");
        //排序0列
        //sortTable(0);
    }

    
//新增行方法
 function insertTR(rowIdx){
        window.mytab.insertRow(rowIdx);
    }

    
//删除行方法
 
function deleteTR(rowIdx){
        window.mytab.deleteRow(rowIdx);
    }

    
//更新列内容
 function updateCell(rowIdx,colIdx,content){
        window.mytab.rows[rowIdx].cells[colIdx].innerText 
= content;
    }

    
//表格排序
 function sortTable(colIdx){
        
var colDataRows = mytab.rows;
        
var allTrs = new Array;

        
for(var i=0; i<colDataRows.length; i++){
            allTrs.push(colDataRows[i]);
        }


        allTrs.sort(genrateCompare(colIdx));
        
        
var o = document.createDocumentFragment();
        
for ( var i=0; i<allTrs.length; i++){
            o.appendChild(allTrs[i]);
        }

        mytab.tBodies[
0].appendChild(o);
    }


    
function genrateCompare(colIdx){
        
return function compareTRs(tr1,tr2){
            
var value1 = tr1.cells[colIdx].innerText;
            
var value2 = tr2.cells[colIdx].innerText;
            
return value1.localeCompare(value2);
        }
;
    }








数据库题:
1.在Person表有以下字段
id
name    人员姓名
deptno    部门号
pdate    入职时间

每新来一个员工就新增一条数据
当员工换部门的时候也新增一条数据
要求:
a。查出'2008-08-01'这天入职的人
b.查出'abc'部门现有的员工资料
sql脚本:
mysql

create table Person(
    id 
int primary key,
    name 
varchar(32),
    deptNo 
varchar(32),
    pdate date
);

insert into person (id,name,deptNo,pdate) values(1,'illu','abc','2008-08-01');
insert into person (id,name,deptNo,pdate) values(2,'satan','ab','2008-08-01');
insert into person (id,name,deptNo,pdate) values(3,'bob','abc','2008-08-01');
insert into person (id,name,deptNo,pdate) values(4,'illu','ab','2008-08-03');
insert into person (id,name,deptNo,pdate) values(5,'satan','abc','2008-08-03');

oracle
create table Person(
    id 
int primary key,
    name 
varchar(32),
    deptNo 
varchar(32),
    pdate date
);

insert into person (id,name,deptNo,pdate) values(1,'illu','abc',to_date('2008-08-01','yyyy-mm-dd'));
insert into person (id,name,deptNo,pdate) values(2,'satan','ab',to_date('2008-08-01','yyyy-mm-dd'));
insert into person (id,name,deptNo,pdate) values(3,'bob','abc',to_date('2008-08-01','yyyy-mm-dd'));
insert into person (id,name,deptNo,pdate) values(4,'illu','ab',to_date('2008-08-03','yyyy-mm-dd'));
insert into person (id,name,deptNo,pdate) values(5,'satan','abc',to_date('2008-08-03','yyyy-mm-dd'));
答案
mysql
a:
select * from person where pdate=date('2008-08-01');

b:
select p.name,p.deptno from
(
select max(id)bid,name from person group by name) b
left join person p
on p.id=b.bid where p.deptno='abc';

oracle
a:
select * from person where pdate=to_date('2008-08-01','yyyy-mm-dd');

b:
select p.name,p.deptno from
(
select max(id)bid,name from person group by name) b
left join person p
on p.id=b.bid where p.deptno='abc';

 2.存储过程和函数的区别
答案
1.    一般来说,存储过程实现的功能要复杂一点,而函数的实现的功能针对性比较强。
2.    对于存储过程来说可以返回参数,而函数只能返回值或者表对象。
3.    存储过程一般是作为一个独立的部分来执行,而函数可以作为查询语句的一个部分来调用,由于函数可以返回一个表对象,因此它可以在查询语句中位于FROM关键字的后面。
 4.    当存储过程和函数被执行的时候,SQL Manager会到procedure cache中去取相应的查询语句,如果在procedure cache里没有相应的查询语句,SQL Manager就会对存储过程和函数进行编译。




每天进步一点点

posted on 2008-08-07 15:03 应越 阅读(386) 评论(1)  编辑  收藏 所属分类: 面试

评论:
# re: 宇易通西安研发部面试题 2011-12-21 15:15 | www
你感觉这家公司如何呢?  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: