java方式来写js程序(demo)

时间:2010-03-29 19:12:34  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:;core.js"></script><script src="collection.js"></script><script>var a="74,77,74,74,89,45,45,55,89";//"74,77,89,45,55"var arr=a.split(",");var set=new HashSet();set.addAll(Arrays.asList(arr));a=set.toArray();alert(a);</script&...
  正文:JavaScript应用是非常广泛的,而且功能特别强大,但是javascript程序就是没有java代码好看,这点是好无疑问的,不过因为js应用太广了,在web应用中几乎离不开它,我初学js,总想像写java程序那样写js。

一个是过滤相同的元素:
<script src="core.js"></script>
<script src="collection.js"></script>
<script>
var a="74,77,74,74,89,45,45,55,89";
//"74,77,89,45,55"
var arr=a.split(",");
var set=new HashSet();
set.addAll(Arrays.asList(arr));
a=set.toArray();
alert(a);
</script>

另一个程序完全是模拟CGI的:
<script src="core.js"></script>
<script src="collection.js"></script>
<style>
td{
 font-size:12px;
}
th{
 font-size:14px;
}
</style>

<body>

<table width="50%" align="center">
<tr>
 <td>用户名称:<input type="text" id="search_name"></td>
 <td><a href="#" onClick="searchUser()">查找用户</a></td>
</tr>
</table>
<div id="list_table" align="center">

</div>

<table width="50%" align="center">
<tr>
 <td>用户ID:<input type="text" id="txt_id"></td>
 <td>用户名称:<input type="text" id="txt_name"></td>
 <td><a href="#" onClick="addUser()">添加用户</a></td>
</tr>
</table>
</body>
<script>
function User(id,name){
 this.id=id;
 this.name=name;
 this.equals=equals;
 function equals(obj){
  return this.id==obj.id;
 }
 this.compareTo=compareTo;
 function compareTo(obj){
  return 1;
 }
}

function AscID(){
 this.compare=compare;
 function compare(obj1,obj2){
  if(obj1.id>obj2.id) return 1;
  else if(obj1.id==obj2.id) return 0;
  else return -1;
 }
}


function DescID(){
 this.compare=compare;
 function compare(obj1,obj2){
  if(obj1.id>obj2.id) return -1;
  else if(obj1.id==obj2.id) return 0;
  else return 1;
 }
}


var table=document.getElementById("list_table");
var list=new SortedList();
var buffer=new ArrayList();
buffer.add(new User("100","Heery"));
buffer.add(new User("101","Marry"));
buffer.add(new User("102","JIM"));
buffer.add(new User("200","Bush"));
buffer.add(new User("201","Eey"));
buffer.add(new User("203","Boy"));
buffer.add(new User("300","Oush"));
buffer.add(new User("1111111","胡江涛"));
buffer.add(new User("2324424","温家宝"));
buffer.add(new User("24325324","刘淇"));
buffer.add(new User("245325353","吴树根"));

list.setComparator(new AscID());
list.addAll(buffer);
//var id_asc=true;


var pageSize=10;
var curPage=1;

function  getTotalPage(){
 return Math.ceil((list.size()/pageSize));
}
function getNavigation(){
 var nav="<tr><td colspan=2>";
 nav+="<a href='#' onClick='firstPage()'>首页</a>&nbsp;&nbsp;";
 nav+="<a href='#' onClick='prePage()'>上一页</a>&nbsp;&nbsp;";
"java方式来写js程序(demo)"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/JavaScript/13393.html


关键字:

关于《java方式来写js程序(demo)》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td