按照我一贯的web开发风格,所有不直接操作数据库的事件,都尽可能由javascript来实现,所以这个需求我打算使用js来完成。
首先来分析一下具体情况:这个页面是一个更新页面,品牌有品牌1和品牌2两个字段,品牌2可以为空,品牌1不能为空,所以品牌2的下拉列表框比品牌1多一项;如果选择了品牌的前8相中的任意一项,“活跃状态”要隐藏,否则“活跃状态”默认显示状态为“潜在”;当查询的结果品牌1和品牌2有任意一项在品牌的前8相中,“活跃状态”也要隐藏,否则“活跃状态”默认显示状态为“潜在”。
页面部分内容
复制代码 代码如下:
<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>
javascript代码
复制代码 代码如下:
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";
}
}
}
首先来分析一下具体情况:这个页面是一个更新页面,品牌有品牌1和品牌2两个字段,品牌2可以为空,品牌1不能为空,所以品牌2的下拉列表框比品牌1多一项;如果选择了品牌的前8相中的任意一项,“活跃状态”要隐藏,否则“活跃状态”默认显示状态为“潜在”;当查询的结果品牌1和品牌2有任意一项在品牌的前8相中,“活跃状态”也要隐藏,否则“活跃状态”默认显示状态为“潜在”。
页面部分内容
复制代码 代码如下:
<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>
javascript代码
复制代码 代码如下:
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";
}
}
}
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]