朋友出去面试做的面试题,分享了下,我就拿来做做。原题:
HTML中有个下拉框,包含“风,雨,雷,电”,添加事件,当选择风时,文本域内出现选择
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form name="form_name" >
<select name="select_name" onChange="ShowToText(); " >
<option value="1">风</option>
<option value="2">雨</option>
<option value="3">雷</option>
<option value="4">电</option>
</select><br>
<textarea rows="3" cols="30"name="textfield_name3">
</textarea>
</form>
</body>
<script language="JavaScript">
function ShowToText(){
document.form_name.textfield_name3.value=document.form_name.select_name.options[document.form_name.select_name.selectedIndex].text
}
</script>
</html>
运行效果