我知道很多PHP,但对Javascript知之甚少.
基本上,我想要的是:
如果用户从HTML表单选择框中选择项目x,则项目x的描述性文本将自动填充其下方的HTML表单输入文本框.
有没有人有我可以使用或编辑的工作样本,以便能够做我需要的?
这是一个使用没有库的纯JavaScript的工作副本:
<script type="text/javascript">
// Pre populated array of data
var myData = new Array();
myData[1] = 'Some text';
myData[2] = 'Some other text';
</script>
<form id="example" name="example">
<select id="selector" name="selector">
<option value="" selected></option>
<option value=1>One</option>
<option value=2>Two</option>
</select>
<br />
<input type="text" value="" id="populateme" name="populateme" />
</form>
<script type="text/javascript">
document.example.selector.onchange = updateText;
function updateText() {
var obj_sel = document.example.selector;
document.example.populateme.value = myData[obj_sel.value];
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
50736 次 |
| 最近记录: |