代码示例
<!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>
<script language="javascript">
function change()
{
var txt1=document.getElementById('text1').value
var obj=document.getElementById('sel1')
var txt2=obj.options[obj.selectedIndex].innerHTML
document.getElementById('div1').innerHTML=txt1+"<br>"+txt2
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body onload="change()">
<form id="test" action="">
<input type="text" value="如何取得该值,并显示?" id='text1' onkeyup="change()" onfocus="this.select()"/>
<select name="select" id='sel1' onchange="change()">
<option value="0" selected="selected">Hello</option>
<option value="2">hi</option>
</select>
</form>
<div id=div1></div>
</body>
</html>
本文提供了一个使用JavaScript实现的简单示例,演示了如何在文本框输入改变及下拉菜单选项变动时动态更新页面上的内容。具体实现包括获取文本框的值与选择的下拉选项,并将这些值拼接后显示到指定的HTML元素中。
1137

被折叠的 条评论
为什么被折叠?



