<script>
function test(){
var oOption = new Option();
oOption.text=document.form1.mxh.value
document.form1.mxh2.options[0]=oOption
}
</script>
<form name=form1>
<input name=mxh onkeydown="test()" type=text>
<select name=mxh2>
<option >
</select>
</form>
function test(){
var oOption = new Option();
oOption.text=document.form1.mxh.value
document.form1.mxh2.options[0]=oOption
}
</script>
<form name=form1>
<input name=mxh onkeydown="test()" type=text>
<select name=mxh2>
<option >
</select>
</form>
解决方案 »
- ext tabpanel问题,高手请帮忙
- 闭包的函数参数传递的疑问?
- 用appendChild增加新行时,document.getElementById(...)为空或不是对象问题 麻烦大家进来看看
- 关于tomcat加载servlet出错的问题,提示:HTTP Status 405 - HTTP method GET is not supported by this URL
- 关于正则表达式
- 关于日历的问题,想了好久,不知怎样解决
- 自己写的的滚动条,动不动就超出外框几像素。
- 寫了個文本閱讀器練練手
- 怎样判断分辨率,让弹出窗口全屏
- toFixed遇到了奇怪的问题
- 请问document.write的一个问题,大家进来看看
- 怎样用JavaScrip编写网页中的漂浮物?
<script>
function autoComplete (field, select, property, forcematch) {
var found = false;
for (var i = 0; i < select.options.length; i++) {
if (select.options[i][property].indexOf(field.value) == 0) {
found=true; break;
}
}
if (found) { select.selectedIndex = i; }
else { select.selectedIndex = -1; }
if (field.createTextRange) {
if (forcematch && !found) {
field.value=field.value.substring(0,field.value.length-1);
return;
}
var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
if (cursorKeys.indexOf(event.keyCode+";") == -1) {
var r1 = field.createTextRange();
var oldValue = r1.text;
var newValue = found ? select.options[i][property] : oldValue;
if (newValue != field.value) {
field.value = newValue;
var rNew = field.createTextRange();
rNew.moveStart('character', oldValue.length) ;
rNew.select();
}
}
}
}</script>
<FORM><B>自动完成</B><BR>请输入123……<BR>
<INPUT onkeyup="autoComplete(this,this.form.options,'value',true)" name=input1>
<SELECT name=options>
<OPTION value=1www selected>1www
<OPTION value=12eee selected>12eee
<OPTION value=123rr selected>123rr
<OPTION value=孟宪会之精彩世界>孟宪会之精彩世界</OPTION>
</SELECT>
</FORM>
1。比如在text输入a,下拉框显示数据库中第一个字母是a的所有项目;接着输入b时,下拉框显示数据库中头2个字母是ab的所有项目;以此类推。
2。在下拉框中每选择一个项目,在另一个页面显示这个项目。
我的qq是53380796,我们可以细谈!
* FileName: DynaSelection.js
* Author: Xu Jie
* Create: 2001-07-19
* Version: 1.0
* Description:
* ----------------------------------------------------------------------------
* Copyright (c) 2001 by XUJIE.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Fields:
* ----------------------------------------------------------------------------
* value
* - The value of selection
* ----------------------------------------------------------------------------
* Methods:
* ----------------------------------------------------------------------------
* init()
* - Set The options list into the selection and draw them on the html page.
* addItem()
* - Add one item into list before initialize, the method must be called
* bofore method init is called.
* getSelection()
* - Once user type a charactor in the text box, the method will be called.
* The method is to select correct values from selection option list.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Example:
* ----------------------------------------------------------------------------
* <script language="JavaScript" src="DynaSelection.js"></script>
* <script language="JavaScript">
* var ds = new DynaSelection();
*
* ds.addItem("Option1");
* ds.addItem("Option2");
* ds.addItem("Option3");
*
* ds.init();
* </script>
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/var arrList = new Array();
var idxList = 0;
var value;/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*/
function DynaSelection() { this.value = value; this.init = Selection_Initialize;
this.addItem = Selection_Add_Item;
this.getSelection = Selection_Get_Result;
}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
function Selection_Initialize() {
document.write("<input type=\"text\" name=\"DynaSelection_Text\" value=\"\" onKeyUp=\"Selection_Get_Result()\"><br>");
document.write("<select name=\"DynaSelection_Select\" multiple size=10 style=\"width:150\">");
for (var i = 0; i < arrList.length; i++) {
document.write("<option>"+arrList[i]+"</option>");
}
document.write("</select>");
}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
function Selection_Add_Item(strItem) {
arrList[idxList++] = strItem;
}/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
function Selection_Get_Result() {
var subArr = new Array();
var index = 0; if (window.event.srcElement.value != "") { var subStr = window.event.srcElement.value; for (var i = 0; i < arrList.length; i ++ ) {
if (arrList[i].substring(0,subStr.length).toUpperCase() == subStr.toUpperCase()) {
subArr[index++] = arrList[i];
}
}
DynaSelection_Select.options.length = index;
}
else {
DynaSelection_Select.options.length = arrList.length;
subArr = arrList;
}
for (var i = 0; i < subArr.length; i ++) {
DynaSelection_Select.options[i].text = subArr[i];
} value = window.event.srcElement.value;
}