1,判断下拉菜单的值是否满足条件
if(document.Form1.dropdownlist1.value=="请选择")
{
alert("对不起,请你选择类型,以防止你出错!!!");
return false;
}
function IsNull()
{ document.getElementById("TextBox1").value
if(document.form1.txtVersion.value=="")
{
alert("Version不能为空");
document.form1.txtVersion.focus();
return false;
}
return true;
}
/
2,判断文本框的值是否满足条件
if(document.Form1.tb_title.value=="")
{
alert("主题不能为空");
document.Form1.tb_title.focus();return false;//让焦点放在该文本矿上
}
/
3,在客户端控制某些组建是否显示
function show()
{
document.all.TextBox2.style.display="none";
if(document.all.CheckBox1.checked) //判断复选框的情况下 //此时为显示
{
document.all("tr1").style.display='none';也可以这样写
document.all.Label1.style.display="";
document.all.Label1.style.display="block";其中block可以省略,表示可以显示
document.all.Label1.style.display='block';也可以用单引号
document.all.TextBox1.style.display="";
}
Else //此时不显示
{
document.all.Label1.style.display="none";
document.all.TextBox1.style.display="none";
}
}
/
4,执行另一个函数允许最大的执行时间
function tm()
{
setTimeout("showinfo();",100);
}
/
5,选择另一个页面,以获得日期组建
function selectDateFun(obj)
{
var a=obj.value;
obj.value=window.showModalDialog("../date_time/CM_date_week.aspx",null,"dialogWidth:300px;dialogheight:190px");
if(obj.value=="undefined")
obj.value=a;
}
/
6,《1》日期控件的html代码(当然还有很多其他更多功能)
<asp:calendar id="Calendar1" style="Z-INDEX: 101; LEFT: 3px; POSITION: absolute; TOP: 2px" runat="server"
Font-Size="9pt" BorderWidth="1px" BackColor="Info" Width="280px" ForeColor="Black" Height="136px"
Font-Names="Verdana" BorderColor="DeepSkyBlue" NextPrevFormat="ShortMonth" ShowDayHeader="True">
<TodayDayStyle BackColor="#CCCCCC"></TodayDayStyle>
<NextPrevStyle Font-Size="8pt" Font-Bold="True" ForeColor="#333333" VerticalAlign="Bottom"></NextPrevStyle>
<DayHeaderStyle Font-Size="8pt" Font-Bold="True"></DayHeaderStyle>
<SelectedDayStyle ForeColor="White" BackColor="#333399"></SelectedDayStyle>
<TitleStyle Font-Size="10pt" Font-Bold="True" BorderWidth="2px" ForeColor="#333399" BorderColor="Black"
BackColor="White"></TitleStyle>
<OtherMonthDayStyle ForeColor="#999999"></OtherMonthDayStyle>
</asp:calendar>
《2》 对应的前台函数:
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
DateTime date=Convert.ToDateTime(Calendar1.SelectedDate);
Response.Write("<script>window.returnValue='"+date.ToString("yyyy-MM-dd")+"';window.close();</script>");
}
/
7,三级联动:
《1》后台代码(对前台起辅助作用,点击按钮后由于刷新问题来保存当前值)
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{简单的取值方法
string guojia=this.ddl_guojia.SelectedItem.Text;
string shengfen=this.Request.Form["ddl_shengfen"].ToString();
string shi=this.Request.Form["ddl_shi"].ToString();
this.TextBox1.Text=guojia+","+shengfen+","+shi;
Response.Write(@"<script>
var var_shengfen='"+shengfen+@"';
var var_shi='"+shi+@"';
</script>");
}
《2》前台代码:
<script language="javascript">
var items_guojia=new Array();
var items_shengfen=new Array();
var items_diqu=new Array();
var xmldom=new ActiveXObject("Microsoft.XMLDOM");//当前可用最新版本
xmldom.async=false;
xmldom.load("../xml/xml_tactic.xml");
var nodelist=xmldom.documentElement.childNodes;
items_guojia=xmldom.selectNodes("//NewDataSet/Table1/guojia");
items_shengfen=xmldom.selectNodes("//NewDataSet/Table1/shengfen");
items_diqu=xmldom.selectNodes("//NewDataSet/Table1/diqu");
function save_sheng()
{
try {
for(var i=0;i<document.Form1.ddl_shengfen.length;i++)
{
if(document.Form1.ddl_shengfen.options[i].value==var_shengfen)
{
document.Form1.ddl_shengfen.selectedIndex=i;
break;
}
}
}
catch(e) {return;}
}
function save_shi()
{
try {
for(var i=0;i<document.Form1.ddl_shi.length;i++)
{
if(document.Form1.ddl_shi.options[i].value==var_shi)
{
document.Form1.ddl_shi.selectedIndex=i;
break;
}
}
}
catch(e) {return;}
}
function shengfen(guojia_value)//从ddl_guojia那里传来所选国家的值
{
var flag;
var ddl_dangqian_len=0;//记录ddl_shengfen的当前项目个数,也就是长度
document.all.ddl_shengfen.length=0;//清除原始记录作用
for(i=0;i<items_guojia.length;i++)
{
if(items_guojia[i].text==guojia_value)//过滤&添加省份
{
flag=false;
for(j=0;j<ddl_dangqian_len;j++)//判断ddl_guojia的项目中是否有重复的
{
if(items_shengfen[i].text==document.Form1.ddl_shengfen.options[j].value)
{
flag=true;
break;
}
}
if(flag==false)
{
var newOption=document.createElement("Option");
newOption.text=items_shengfen[i].text;
newOption.value=items_shengfen[i].text;
document.all.ddl_shengfen.options.add(newOption);
ddl_dangqian_len++;
}
}
}
save_sheng()
shi(document.Form1.ddl_shengfen.value)
}
function shi(shengfen_value)
{
document.all.ddl_shi.length=0;
for(i=0;i<items_shengfen.length;i++)
{
if(items_shengfen[i].text==shengfen_value)
{
var newOption=document.createElement("Option");
newOption.text=items_diqu[i].text;
newOption.value=items_diqu[i].text;
document.all.ddl_shi.options.add(newOption);
}
}
save_shi()
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table width="100%" border="1">
<tr>
<td>国家:
<asp:dropdownlist id="ddl_guojia" runat="server" οnchange="shengfen(this.value)" Width="112px">
<asp:ListItem Value="中国">中国</asp:ListItem>
<asp:ListItem Value="美国">美国</asp:ListItem>
</asp:dropdownlist></td>
<td>省份:
<asp:dropdownlist id="ddl_shengfen" runat="server" οnchange="shi(this.value)" Width="112px"></asp:dropdownlist></td>
<td>市:<asp:dropdownlist id="ddl_shi" runat="server" Width="112px"></asp:dropdownlist></td>
<td><asp:imagebutton id="ImageButton1" runat="server" ImageUrl="../image/btn_search.gif"></asp:imagebutton></td>
</tr>
<tr>
<td colspan="4">
<asp:TextBox id="TextBox1" runat="server" Width="100%"></asp:TextBox></td>
</tr>
</table>
</form>
<script>
shengfen(document.Form1.ddl_guojia.value);
</script>
</body>
</HTML>
/
8,Repeater的一些用法:
<asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<table border="0" width="100%" background="leftbg.gif">
<tr>
<td>--------<font color="#66cc66">
<%# DataBinder.Eval(Container.DataItem, "name") %>
</font>于 <font color="#ff66cc">
<%# DataBinder.Eval(Container.DataItem, "date").ToString().Substring (0,4) +"年"+DataBinder.Eval(Container.DataItem, "date").ToString().Substring (4,2) +"月"+DataBinder.Eval(Container.DataItem, "date").ToString().Substring (7,2) +"日"+DataBinder.Eval(Container.DataItem, "date").ToString().Substring (10,8)%>
</font>
</td>
</tr>
<tr>
<td width="850px"><br>
<font color="#3366ff">
<pre><%# Server.HtmlDecode(DataBinder.Eval(Container.DataItem, "idea").ToString()) %></pre>
</font>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:repeater>
/
9,显示当前时间函数:
function displayTime()
{
var today=new Date();
var hours=today.getHours();
var minutes=today.getMinutes();
var seconds=today.getSeconds();
minutes=fixTime(minutes);
seconds=fixTime(seconds);
var the_time=hours+":"+minutes+":"+seconds;
window.document.Form1.TextBox1.value=the_time;
the_time=setTimeout('displayTime();',500);
}
function fixTime(the_time)
{
if(the_time<10)
{
the_time="0"+the_time;
}
return the_time;
}
/
10,确定退出函数
function wclose()
{
if(confirm("你确定要退出吗?"))
{
parent.window.opener=null;
parent.window.close();
return true;
}
else
return false;
}
11、留言簿中的时间在reapeater中的显示
<%# DataBinder.Eval(Container.DataItem, "date").ToString().Substring (0,4) +"年"+DataBinder.Eval(Container.DataItem, "date").ToString().Substring (4,2) +"月"+DataBinder.Eval(Container.DataItem, "date").ToString().Substring (7,2) +"日"+DataBinder.Eval(Container.DataItem, "date").ToString().Substring (10,5)%>
12、让table表是否在页面显示:
a,前台实现
if(××)
document.all.tb_xx.style.display="none";
else
document.all.tb_xx.style.display="";
b,后台实现
this.tb_xx.Visible=true;
12、设为主页代码():
<td οnclick="var strHref=window.location.href;this.style.behavior='url(#default#homepage)';this.setHomePage('http://211.97.118.206');">
<IMG src="images/home00.gif" border="0">设为主页</td>
13,后台传参数,前台接参数
a、后台传:
private void dg_dzinfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType.Equals(ListItemType.Item)||e.Item.ItemType.Equals(ListItemType.AlternatingItem))
{
string wxzc=e.Item.Cells[0].Text;
string dz=e.Item.Cells[2].Text;
if(dz.Length>=2)
dz=dz.Substring(0,2);
string tj=e.Item.Cells[1].Text;
((System.Web.UI.WebControls.Image)e.Item.Cells[7].FindControl("Image1")).Attributes.Add("onclick","confir_dz('"+wxzc+"','"+dz+"','"+tj+"')");
((System.Web.UI.WebControls.Image)e.Item.Cells[8].FindControl("Image2")).Attributes.Add("onclick","confir_kaolv('"+wxzc+"','"+dz+"')");
((System.Web.UI.WebControls.Image)e.Item.Cells[9].FindControl("Image3")).Attributes.Add("onclick","confir_jujue('"+wxzc+"','"+dz+"')");
}
}
b、前台接:
function confir_jujue(var1,var2)
{
var cId=document.Form1.tb_id.value;
document.Form1.Text3.value=var1;
if(var1=="增值业务")
{
window.open("wxzc_topic2.aspx?wxzc=拒绝&client_id="+cId,null,'height=450, width=600, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=yes');
}
if(var1=="送话费")
{
if(var2!="考虑"&&var2!="拒绝"&var2!="未处")
{
alert("已定制过不能修改");
return;
}
window.open("wxzc_topic1_jj.aspx?wxzc=拒绝&client_id="+cId,null,'height=450, width=600, top=0, left=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=yes');
return;
}
if(var1!="增值业务"&&var1!="送话费")
{
if(var2!="考虑"&&var2!="拒绝"&var2!="未处")
{
alert("已定制过不能修改");
return;
}
if(confirm('您确定要提交拒绝吗?来源是'+document.Form1.ddl_tj.value+'吗?'))
{
__doPostBack("jujue","");
return;
}
}
}
14,该单选按钮的地前台属性是:<asp:radiobuttonlist id="RadioButtonList1" οnclick="radio_checked();" runat="server" Width="224px" RepeatDirection="Horizontal" Height="24px">
<asp:ListItem Value="1">单个录入</asp:ListItem>
<asp:ListItem Value="2">批录入</asp:ListItem></asp:radiobuttonlist>
关于它的一些前台操作如下:
function radio_display()
{
document.Form1.File1.style.display="none";
document.all.Label1.style.display="none";
document.all.Label5.style.display="none"//服务器控件用all,html控件用Form1
document.Form1.RadioButtonList1_0.checked=true;
}
function radio_checked()
{
if(document.Form1.RadioButtonList1_0.checked==true)
{
。。。。。。
}
if(document.Form1.RadioButtonList1_1.checked==true)
{
。。。。。。
}
}
function text_clear()
{
if(document.Form1.RadioButtonList1_0.checked==false && document.Form1.RadioButtonList1_1.checked==false)
{
alert("请选择录入方式!!!")
return false;
}
return true;
}
15,滚动文字的写法:
<marquee οnmοuseοver="this.stop()" οnmοuseοut="this.start()" direction="left">无忧办公系统(我的毕业设计)</marquee>
16,页面间的跳转并传递参数
window.location.href="b.asp?dr="+a+"drr="+c;
17,<!--要弹出的页面中,一定要保证<head></head>标签间有<base target=“_self”>,否则 弹出的模态窗口上,点击按钮时,会再次弹出一个新页面 -->
<base target="_self"/>
<!-- 清除模态窗口页面缓存-->
<meta http-equiv="Pragma" content="no-cache"/>
window.showModalDialog("../Dispatch/ShowModelForm.aspx",arrayObj,"dialogHeight:"+open_height+"px;dialogWidth:"+open_width+"px;dialogLeft:"+open_left+"px;dialogTop:"+open_top+"px;center:yes;resizable:no;toolbar:no;status:no;help:no;menubar:no;location:no;scroll:on");
18,让一个控件的Eable是否可用:
允许:document.getElementById("btnTestSet").disabled=false;
禁止:document.getElementById("btnTestSet").disabled=true;
19,grid某列的复选框全:
19.1 JScript:
function SelectAll(chkVal, idVal)
{
var thisfrm = document.forms[0];
// 查找Forms里面所有的元素
for (i=0; i<thisfrm.length; i++)
{
// 查找模板头中的CheckBox
if (idVal.indexOf('chkHead')!= -1)
{
if(chkVal == true)
{
if(thisfrm.elements[i].id.indexOf('chkItem')!=-1)
{
thisfrm.elements[i].checked = true;
}
}
else
{
if(thisfrm.elements[i].id.indexOf('chkItem')!=-1)
{
thisfrm.elements[i].checked = false;
}
}
}
} // for循环结束
return false;
}
19.2 CheckBox:
<input id="chkHead" runat="server" οnclick="SelectAll(this.checked,this.id);" type="checkbox" />
<input id="chkItem" runat="server" type="checkbox" />
19.3 后台获得:
bool isSelect = ((HtmlInputCheckBox)this.gridUsers.Rows[i].FindControl("chkItem")).Checked;
20 grid某列的单选按钮:
20.1 jscript
function SetValue(rd)
{
document.getElementById("hidenGridIndex").value = rd.value;//将radio记录的行号作为一个隐藏的控件值,后天或去该隐藏文件的值
}
20.2 html
<asp:HiddenField ID="hidenGridIndex" runat="server" Value="no" />
<input id="myRadio" name="myRadio" οnclick="SetValue(this)" type="radio" value="<%# Container.DataItemIndex.ToString() %>">
value="<%# Container.DataItemIndex.ToString() %>"作用是生成grid的时候,将行号作为radio的值
20.3 后台
string rowIndex = this.hidenGridIndex.Value;