<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
function test()
{
var num=document.getElementById("in").value;
var type=document.getElementById("title");
var tynum,to;
for(var i=0;i<type.length;i++)
{
if(type[i].selected)
tynum=parseInt(type[i].value);
}
switch(tynum)
{
case(1):to=parseInt(num).toString(2);break;
case(2):to=parseInt(num).toString(8);break;
case(3):to=parseInt(num).toString(16);break;
case(4):to=parseInt(num,2);break;
case(5):to=parseInt(num,8);break;
case(6):to=parseInt(num,16);break;
case(7):to=parseInt(num,2).toString(8);break;
case(8):to=parseInt(num,8).toString(2);break;
case(9):to=parseInt(num,2).toString(16);break;
case(10):to=parseInt(num,16).toString(2);break;
case(11):to=parseInt(num,8).toString(16);break;
case(12):to=parseInt(num,16).toString(8);break;
}
if(isNaN(to))
to="输入非法字符了哦"
document.getElementById("out").value=to;
}
</script>
<select name="title" >*注:存在非法字符时,我们只截断有效字符进行转换</font>
</body>
</html>
相关文章: