页面版文本框智能提示JS代码,操作select下拉列表
分类:前端技术

依据笔者一定的web开荒风格,全数不间接操作数据库的事件,都不遗余力由javascript来促成,所以这些供给本人希图利用js来形成。
首先来剖判一下具体意况:那几个页面是三个翻新页面,品牌有品牌1和品牌2多个字段,品牌2足以为空,品牌1无法为空,所以品牌2的下拉列表框比品牌1多一项;假诺接纳了品牌的前8相中的任性一项,“活跃状态”要藏匿,不然“活跃状态”私下认可突显状态为“潜在”;当查问的结果品牌1和品牌2有自由一项在品牌的前8相中,“活跃状态”也要藏匿,不然“活跃状态”暗许呈现状态为“潜在”。
页面部分剧情

于是乎那code便诞生了,如下:

于是乎那code便诞生了,如下:

复制代码 代码如下:

复制代码 代码如下:

复制代码 代码如下:

<div id="div_Brand_Baby" name="div_Brand_Baby" style="display: none" runat="server">
<div style="float: left;">品牌1:</div>
<div style="position: relative; float: left;">
<span style="margin-left: 170px; width: 18px; overflow: hidden;">
<atlas:UpdatePanel ID="UpdatePanel12" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlistFirstConsumeBrand" onchange="ChangeBrand(this)" runat="server"
DataTextField="OptionText" DataValueField="optionValue" DataSourceID="ObjectDataSource11"
Style="width: 188px; margin-left: -170px">
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>
</span>
<asp:TextBox ID="txtBrand1" runat="server" onblur="changebrand1(this)" Style="width: 170px;
position: absolute; left: 0px;"></asp:TextBox>
</div>
<div style="float: left;">
  品牌2:</div>
<div style="position: relative; float: left;">
<span style="margin-left: 170px; width: 18px; overflow: hidden;">
<atlas:UpdatePanel ID="UpdatePanel13" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlistSecondConsumeBrand" runat="server" onchange="ChangeBrand(this)"
DataTextField="OptionText" DataValueField="optionValue" DataSourceID="ObjectDataSource12"
Style="width: 188px; margin-left: -170px">
</asp:DropDownList>
</ContentTemplate>
</atlas:UpdatePanel>
</span>
<asp:TextBox ID="txtbrand2" runat="server" onblur="changebrand1(this)" Style="width: 170px;
position: absolute; left: 0px;"></asp:TextBox>
</div>
<asp:ObjectDataSource ID="ObjectDataSource11" runat="server" SelectMethod="RetrieveMilkBrand_Baby"
TypeName="CRR.BusinessRules.OptionManager">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="languageID" Type="Int32" />
<asp:Parameter DefaultValue="false" Name="addNull" Type="Boolean" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource12" runat="server" SelectMethod="RetrieveMilkBrand_Baby"
TypeName="CRR.BusinessRules.OptionManager">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="languageID" Type="Int32" />
<asp:Parameter DefaultValue="true" Name="addNull" Type="Boolean" />
<asp:Parameter DefaultValue=" " Name="nullString" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</div>

<html xmlns="" >
<head runat="server">
<title>无题目页</title>
<script type="text/javascript" language="javascript">
var currentIndex=-1;//保存提示框中精选的目录
var sumSearchCount=0;//保存提醒框中数据数量
var tempValue="";//保存当前输入的要寻找的内容
var objTxt="";//保存文本框对象
var top=0;//提醒框的top
var left=0;//提醒框的left
var width=0;//提醒框的width
var values = new Array();//保存下拉列表的值
var texts = new Array();//保存下拉列表的显得内容
var tempDiv=new Array();//保存提示框中索引对应的values索引
//获取下拉列表的值和展现内容
function getSelectValues(ddl){
ddlvalue = document.getElementById("DropDownList1");
for(var i=0;i<ddlvalue.length;i ){
values[i]=ddlvalue.options[i].value;
texts[i]=ddlvalue.options[i].text;
}
}
var oInterval = "";//保存自动计时对象
function fnStartInterval(txt_id){
getSelectValues("DropDownList1");
objTxt=txt_id;//获取输入文本框对象
top = getLength("offsetTop") objTxt.offsetHeight;
left= getLength("offsetLeft");
width=objTxt.offsetWidth;
oInterval = window.setInterval("beginSearch()",两千);//启用计时
}
//获取对应属性的尺寸
function getLength(attribute)
{
var offset = 0;
var txt_input = document.getElementById("txtSearch");
while (item)
{
offset = txt_input[attribute];
txt_input = txt_input.offsetParent;
}
return offset;
}
//截至计时
function fnStopInterval()
{
window.clearInterval(oInterval);
}
//自动完结提醒
function beginSearch(){
if(objTxt.value.length>0 && tempValue!=objTxt.value)
{
sumSearchCount=0;
tempValue=objTxt.value;
var div_show = document.getElementById("divMsg");
div_show.style.top=top "px";
div_show.style.display="block";
div_show.style.left=left "px";
div_show.style.width=width "px";
div_show.innerHTML="";
var leng = texts.length;
var txt_value = objTxt.value;
var row="";
for(var i=0;i<leng;i ){
if(texts[i].indexOf(txt_value)!=-1){
row = row "<div style="font-size:14px; display:block; width:100%" id='divsearch_" i "' onmouseover="this.style.backgroundColor='#3366CC';currentIndex=" i ";" onmouseout="this.style.backgroundColor='';currentIndex=-1;" onclick="span_click(this)" >" texts[i] "</div>";
tempDiv[sumSearchCount]=i;
sumSearchCount ;
pc28.am神测网,}
}
div_show.innerHTML=row;
}
else if(objTxt.value.length==0 || objTxt.value == null)
{
var div_msg = document.getElementById("divMsg");
div_msg.style.display="none";
div_msg.innerHTML="";
}
}
//提醒内容单击保存到文本框中
function span_click(sp)
{
clear();
objTxt.value=sp.innerHTML;
document.getElementById("DropDownList1").options[sp.id.substring(sp.id.indexOf('_') 1,sp.id.length)].selected="selected";
}
//甘休查询,关闭提示
function closeSearch()
{
var tbl = document.activeElement.parentElement;
if(tbl && tbl.id!="divMsg")//幸免利用上下键后不见提示内容
{
clear();
document.getElementById("divMsg").innerHTML="";
}
else if(currentIndex==-1)
{
clear();
document.getElementById("divMsg").innerHTML="";
}
}
//清空提醒
function clear()
{
fnStopInterval();
currentIndex=-1;
tempValue="";
document.getElementById("divMsg").style.display="none";
}
//使用键盘上下方向键和enter键
function changeSelect()
{
var divContent = document.getElementById("divMsg");
if(divContent && divContent.style.display=="block")
{
if (event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 13)
{
if(currentIndex!=-1) document.getElementById("divsearch_" tempDiv[currentIndex]).style.backgroundColor="";
if (event.keyCode == 38 && currentIndex > 0)
{
currentIndex--;
document.getElementById("divsearch_" tempDiv[currentIndex]).style.backgroundColor="#3366CC";
}
else if (event.keyCode == 40 && currentIndex < sumSearchCount-1)
{
currentIndex ;
document.getElementById("divsearch_" tempDiv[currentIndex]).style.backgroundColor="#3366CC";
}
else if (event.keyCode == 13)
{
if(currentIndex > -1)
{
var divpart = document.getElementById("divsearch_" tempDiv[currentIndex]);
objTxt.value=divpart.innerHTML;
document.getElementById("DropDownList1").options[tempDiv[currentIndex]].selected="selected";
clear();
}
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txtSearch" autocomplete="off" onkeydown="changeSelect()" onfocus="fnStartInterval(this)" onblur="closeSearch()" runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="slr_realname" DataValueField="systemloginrecord_id" DataSourceID="ObjectDataSource1" Width="130px">
</asp:DropDownList><asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetRecordDS"
TypeName="TestDAL"></asp:ObjectDataSource>
</div>
<div style="display:none; z-index:2; text-align:left; position:absolute; border:solid 1px;" id="divMsg">
</div>
</form>
</body>
</html>

<html xmlns="" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" language="javascript">
var currentIndex=-1;//保存提醒框中甄选的目录
var sumSearchCount=0;//保存提醒框中数据数量
var tempValue="";//保存当前输入的要查究的剧情
var objTxt="";//保存文本框对象
var top=0;//提醒框的top
var left=0;//提醒框的left
var width=0;//提示框的width
var values = new Array();//保存下拉列表的值
var texts = new Array();//保存下拉列表的体现内容
var tempDiv=new Array();//保存提醒框中索引对应的values索引
//获取下拉列表的值和显示内容
function getSelectValues(ddl){
ddlvalue = document.getElementById("DropDownList1");
for(var i=0;i<ddlvalue.length;i ){
values[i]=ddlvalue.options[i].value;
texts[i]=ddlvalue.options[i].text;
}
}
var oInterval = "";//保存自动计时对象
function fnStartInterval(txt_id){
getSelectValues("DropDownList1");
objTxt=txt_id;//获取输入文本框对象
top = getLength("offsetTop") objTxt.offsetHeight;
left= getLength("offsetLeft");
width=objTxt.offsetWidth;
oInterval = window.setInterval("beginSearch()",三千);//启用计时
}
//获取对应属性的长短
function getLength(attribute)
{
var offset = 0;
var txt_input = document.getElementById("txtSearch");
while (item)
{
offset = txt_input[attribute];
txt_input = txt_input.offsetParent;
}
return offset;
}
//甘休计时
function fnStopInterval()
{
window.clearInterval(oInterval);
}
//自动完成提醒
function beginSearch(){
if(objTxt.value.length>0 && tempValue!=objTxt.value)
{
sumSearchCount=0;
tempValue=objTxt.value;
var div_show = document.getElementById("divMsg");
div_show.style.top=top "px";
div_show.style.display="block";
div_show.style.left=left "px";
div_show.style.width=width "px";
div_show.innerHTML="";
var leng = texts.length;
var txt_value = objTxt.value;
var row="";
for(var i=0;i<leng;i ){
if(texts[i].indexOf(txt_value)!=-1){
row = row "<div style="font-size:14px; display:block; width:100%" id='divsearch_" i "' onmouseover="this.style.backgroundColor='#3366CC';currentIndex=" i ";" onmouseout="this.style.backgroundColor='';currentIndex=-1;" onclick="span_click(this)" >" texts[i] "</div>";
tempDiv[sumSearchCount]=i;
sumSearchCount ;
}
}
div_show.innerHTML=row;
}
else if(objTxt.value.length==0 || objTxt.value == null)
{
var div_msg = document.getElementById("divMsg");
div_msg.style.display="none";
div_msg.innerHTML="";
}
}
//提醒内容单击保存到文本框中
function span_click(sp)
{
clear();
objTxt.value=sp.innerHTML;
document.getElementById("DropDownList1").options[sp.id.substring(sp.id.indexOf('_') 1,sp.id.length)].selected="selected";
}
//甘休查询,关闭提醒
function closeSearch()
{
var tbl = document.activeElement.parentElement;
if(tbl && tbl.id!="divMsg")//幸免利用上下键后不见提醒内容
{
clear();
document.getElementById("divMsg").innerHTML="";
}
else if(currentIndex==-1)
{
clear();
document.getElementById("divMsg").innerHTML="";
}
}
//清空提醒
function clear()
{
fnStopInterval();
currentIndex=-1;
tempValue="";
document.getElementById("divMsg").style.display="none";
}
//使用键盘上下方向键和enter键
function changeSelect()
{
var divContent = document.getElementById("divMsg");
if(divContent && divContent.style.display=="block")
{
if (event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 13)
{
if(currentIndex!=-1) document.getElementById("divsearch_" tempDiv[currentIndex]).style.backgroundColor="";
if (event.keyCode == 38 && currentIndex > 0)
{
currentIndex--;
document.getElementById("divsearch_" tempDiv[currentIndex]).style.backgroundColor="#3366CC";
}
else if (event.keyCode == 40 && currentIndex < sumSearchCount-1)
{
currentIndex ;
document.getElementById("divsearch_" tempDiv[currentIndex]).style.backgroundColor="#3366CC";
}
else if (event.keyCode == 13)
{
if(currentIndex > -1)
{
var divpart = document.getElementById("divsearch_" tempDiv[currentIndex]);
objTxt.value=divpart.innerHTML;
document.getElementById("DropDownList1").options[tempDiv[currentIndex]].selected="selected";
clear();
}
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txtSearch" autocomplete="off" onkeydown="changeSelect()" onfocus="fnStartInterval(this)" onblur="closeSearch()" runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="slr_realname" DataValueField="systemloginrecord_id" DataSourceID="ObjectDataSource1" Width="130px">
</asp:DropDownList><asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetRecordDS"
TypeName="TestDAL"></asp:ObjectDataSource>
</div>
<div style="display:none; z-index:2; text-align:left; position:absolute; border:solid 1px;" id="divMsg">
</div>
</form>
</body>
</html>

javascript代码

<input type="text" id="txtSearch" autocomplete="off"。。。这里参加了autocomplete属性,屏蔽了文本框输入记录提示成效,纵然这一个效果很好,不过在此地却成了障碍。呵呵
先前从未写博客的习贯,繁多有时常采纳的东西用过就忘了。现在是要整治理和整顿理了。

<input type="text" id="txtSearch" autocomplete="off"。。。这里步向了autocomplete属性,屏蔽了文本框输入记录提示效果,尽管那个效用很好,但是在这里却成了阻力。呵呵
原先从未写博客的习贯,好些个不日常选用的事物用过就忘了。以往是要料理整理了。

复制代码 代码如下:

复制代码 代码如下: html xmlns="" head runat="server" title无标题页/title script type="text/javascript"...

你恐怕感兴趣的稿子:

  • 用jQuery与JSONP轻巧消除跨域访问的难点
  • 接纳jsonp完美化解跨域问题
  • 跨域央求之jQuery的ajax jsonp的行使答疑
  • jquery下使用jsonp跨域访问达成格局
  • jquery ajax jsonp跨域调用实例代码
  • 仿百度输入框智能唤起的js代码
  • jQuery在vs二零零六及js文件中的无智能提示的消除方法
  • asp.net 页面版文本框智能提示JSCode (晋级版)
  • JS完毕仿google、百度找出框输入消息智能提醒的贯彻情势
  • 使用jsonp跨域调用百度js达成找寻框智能提示

function changebrand1(oTextbox)
{
var brandTag=document.getElementById("ddlistSecondConsumeBrand");
var brand1=document.getElementById("txtbrand1");
var brand2=document.getElementById("txtbrand2");
var brandcolls=brandTag.options;
var textvalue=oTextbox.value;
var flag=0;
if(textvalue.length==0)
{
flag=1;
}
else if(textvalue.length>0)
{
for(var i=0;i<brandcolls.length;i )
{
if(oTextbox==brand1 && brandcolls[i].text==textvalue)
{
document.getElementById("ddlistFirstConsumeBrand").options.selectedIndex=i-1;
flag=1;
ChangeBrand(document.getElementById("ddlistFirstConsumeBrand"));
}
else if(oTextbox==brand2 && brandcolls[i].text==textvalue)
{
brandTag.selectedIndex=i;
flag=1;
ChangeBrand(brandTag);
}
}

if(flag==0)
{
alert("输入品牌错误!");
oTextbox.value="";
oTextbox.focus();
}
}
}

function ChangeBrand(me){
var brand1ID = document.all.ddlistFirstConsumeBrand.value;
var brand2ID = document.all.ddlistSecondConsumeBrand.value;
var brandvalue1=document.getElementById("txtbrand1");
var brandvalue2=document.getElementById("txtbrand2");
if((brand1ID=="10")&&(brand2ID=="-1"))
{
document.all.ddlistMilkPeriod.value=9;
}

for(var i=0;i<document.getElementById("ddlistSecondConsumeBrand").options.length;i )
{
if(document.getElementById("ddlistFirstConsumeBrand") == me && document.all.ddlistFirstConsumeBrand.selectedIndex==i)
{
brandvalue1.value=document.getElementById("ddlistFirstConsumeBrand").options[i].text;
}
if(document.getElementById("ddlistSecondConsumeBrand") == me && document.all.ddlistSecondConsumeBrand.selectedIndex==i)
{
brandvalue2.value=document.getElementById("ddlistSecondConsumeBrand").options[i].text;
}

if(i<8 && document.getElementById("ddlistFirstConsumeBrand") == me && document.all.ddlistFirstConsumeBrand.selectedIndex==i)
{
document.all.dv1.style.display="block";
document.all.dv2.style.display="none";
document.all.dv3.style.display="none";
document.getElementById("ddlistPotential").options[0].selected="selected";
break;
}
else if(i>0 && i<9 && document.getElementById("ddlistSecondConsumeBrand") == me && document.all.ddlistSecondConsumeBrand.selectedIndex==i)
{
document.all.dv1.style.display="block";
document.all.dv2.style.display="none";
document.all.dv3.style.display="none";
document.getElementById("ddlistPotential").options[0].selected="selected";
break;
}
else if(i>8)
{
document.all.dv1.style.display="none";
document.all.dv2.style.display="block";
document.all.dv3.style.display="block";
document.getElementById("ddlistPotential").options[1].selected="selected";
}
}
}

首先来分析一下...

本文由pc28.am发布于前端技术,转载请注明出处:页面版文本框智能提示JS代码,操作select下拉列表

上一篇:注册下一步实现代码,文本框获得焦点和失去焦 下一篇:没有了
猜你喜欢
热门排行
精彩图文