<!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=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#jobsList {
background-color: #CCC;
width: 200px;
display:none;
margin-top:-14px;
}
#jobs {
width: 200px;
height: 20px;
}
</style>
<script type="text/javascript">
function show()
{
var text = document.getElementById("jobs");
//获取文本框距离左边和上边的距离
var left = text.offsetLeft - 10;
var top = text.offsetTop;
var list = document.getElementById("jobsList");
list.style.marginLeft = left + "px";
list.style.display="block";
}
function closeJobList()
{
var list = document.getElementById("jobsList");
list.style.display="none";
var jobs = document.getElementsByName("job");
var value = "";
for(var i = 0;i<jobs.length;i++)
{
if(jobs[i].checked == true)
{
value = jobs[i].value;
break;
}
}
document.getElementById("jobs").value = value;
}
</script>
</head>
<body>
<form action="" method="get">
请选择您的职业:<input type="text" id="jobs" οnclick="show()"/>
</form>
<div id="jobsList">
<ul>
<li><input type="radio" name="job" value="软件工程师" />软件工程师</li>
<li><input type="radio" name="job" value="硬件工程师"/>硬件工程师</li>
<li><input type="radio" name="job" value="网络工程师" />网络工程师</li>
<li><input type="radio" name="job" value="维修工程师" />维修工程师</li>
<input type="button" value="选择" οnclick="closeJobList()"/>
</ul>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#jobsList {
background-color: #CCC;
width: 200px;
display:none;
margin-top:-14px;
}
#jobs {
width: 200px;
height: 20px;
}
</style>
<script type="text/javascript">
function show()
{
var text = document.getElementById("jobs");
//获取文本框距离左边和上边的距离
var left = text.offsetLeft - 10;
var top = text.offsetTop;
var list = document.getElementById("jobsList");
list.style.marginLeft = left + "px";
list.style.display="block";
}
function closeJobList()
{
var list = document.getElementById("jobsList");
list.style.display="none";
var jobs = document.getElementsByName("job");
var value = "";
for(var i = 0;i<jobs.length;i++)
{
if(jobs[i].checked == true)
{
value = jobs[i].value;
break;
}
}
document.getElementById("jobs").value = value;
}
</script>
</head>
<body>
<form action="" method="get">
请选择您的职业:<input type="text" id="jobs" οnclick="show()"/>
</form>
<div id="jobsList">
<ul>
<li><input type="radio" name="job" value="软件工程师" />软件工程师</li>
<li><input type="radio" name="job" value="硬件工程师"/>硬件工程师</li>
<li><input type="radio" name="job" value="网络工程师" />网络工程师</li>
<li><input type="radio" name="job" value="维修工程师" />维修工程师</li>
<input type="button" value="选择" οnclick="closeJobList()"/>
</ul>
</div>
</body>
</html>