手机
当前位置:查字典教程网 >网页设计 >脚本HTML教程 >为Html的Select加一个提示语和输入方法
为Html的Select加一个提示语和输入方法
摘要:

 <HTML>

<Head>

<SCRIPT LANGUAGE="JavaScript">

<!--

//定义 select 原值

var oldValue,oldText;

//select下拉框的onkeydown事件,修改下拉框的值

function catch_keydown(sel)

{

switch(event.keyCode)

{

case 13: //回车键

event.returnValue = false;

break;

case 27: //Esc键

sel.options[sel.selectedIndex].text = oldText;

sel.options[sel.selectedIndex].value = oldValue;

event.returnValue = false;

break;

case 8: //空格健

var s = sel.options[sel.selectedIndex].text;

s = s.substr(0,s.length-1);

if (sel.options[sel.selectedIndex].value==sel.options[sel.selectedIndex].text)

{

sel.options[sel.selectedIndex].value=s;

sel.options[sel.selectedIndex].text=s;

}

event.returnValue = false;

break;

}

if (!event.returnValue && sel.onchange)

sel.onchange(sel)

}

//select下拉框的onkeypress事件,修改下拉框的值

function catch_press(sel){

if(sel.selectedIndex>=0){

var s = sel.options[sel.selectedIndex].text + String.fromCharCode(event.keyCode);

if (sel.options[sel.selectedIndex].value==sel.options[sel.selectedIndex].text)

{

sel.options[sel.selectedIndex].value=s;

sel.options[sel.selectedIndex].text=s;

}

event.returnValue = false;

if (!event.returnValue && sel.onchange)

sel.onchange(sel)

}

}

//select下拉框的onfocus事件,保存下拉框原来的值

function catch_focus(sel) {

oldText = sel.options[sel.selectedIndex].value;

oldValue = sel.options[sel.selectedIndex].value;

}

//恢复select下拉列表当前选中的值

function LoadSelect(obj,value)

{

for (var i=0; i< obj.options.length; i++)

if (obj.options[i].value == value)

{

obj.selectedIndex = i;

break;

}

}

//select 选择框鼠标上移时提示选择的内容

function selMouseOver(obj)

{

with (document.all.div_hint)

{

innerText = obj.options[obj.selectedIndex].text;

if (innerText.length > 0)

{

innerText = " " + innerText + " ";

style.display = "block";

style.left = event.clientX + 16;

style.top = event.clientY;

}

}

}

//select 选择框鼠标移开时消失

function selMouseOut(obj)

{

with (document.all.div_hint)

{

style.display = "none"

}

}

//-->

</SCRIPT>

</Head>

<Body>

<!--调用-->

<select name='tmpSel' onmouseout=selMouseOut(this) onkeydown=catch_keydown(this) onfocus=catch_focus(this)>

<option value=''></option>

</select>

<!--提示块-->

<div id=div_hint ></div>

</Body>

</Html>

【为Html的Select加一个提示语和输入方法】相关文章:

把Word转为简洁的html的若干种方法

html中有亲和力的文字隐藏方法

html超级链接a的提示和打开方式

html和body标记应用CSS方法和技巧

python通过wxPython打开一个音频文件并播放的方法

HTML的一些关于颜色方面的参考

html中的checkbox复选框不确定状态的设置

html css将表头固定的最直接的方法

清空select标签中option选项的3种不同方式

python中日期和时间格式化输出的方法小结

精品推荐
分类导航