小小代码留着有用【自己做项目学到得就是比老师交的映像深刻】
2012-11-20 18:40
288 查看
1.实现居中
在td标签中加入属性align="center"(这个是左右居中)valign="middle"(这个是上下居中)
例:
<table>
<tr><td align="center" valign="middle">图片文字居中现实代码</td></tr>
</table>
2.绝对定位
<style type="text/css">
#div3
{
position:absolute;
top:100px;
right:267px;
}
</style>
3.图片去边框
img
{
border:none;}
4.超链接去下滑线
a
{
text-decoration:none;
}
<a href="连接到得页">作业</a>
5.将盒子的边框显示出来
<div id="div2" style="border: 2px solid Red; width:211px; height:563px;">
设置盒子在指定的位置
<div id="hezi" style="border: 1px solid Red;width:800px; height:350px; text-align:center;margin-left:200px;position:relative;top:120px; " >
6.加*并使*变成红色
<span class ="w">*</span>
.w
{
color:Red ;
}
7、设置一个图片按钮
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/zhanglan/zhuze.jpg" />
8.验证码
<td id ="d"><img id="yanzhengma" src="yanzhengma.aspx" onclick="this.src='yanzhengma.aspx?aaa='+new Date()" alt="" />
<a href="javascript:Verify();">看不清楚,换张图片 </a>
</td>
<script type="text/javascript" >
function Verify()
{
document.getElementById("yanzhengma").src = "yanzhengma.aspx?time=" + Math.random();
}
</script>
protected void Page_Load(object sender, EventArgs e)
{
System.Random r = new Random();
string s = Convert.ToString(r.Next(1000, 9999));//验证码数字
string path = Server.MapPath("~/images/zhanglan/1.jpg");
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(path))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
g.DrawString(s, new System.Drawing.Font("宋体", 30), System.Drawing.Brushes.Red, 0, 0);
}
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Session["index"] = s;
}
----------------------------------------------------
9.图片按钮转向另一个界面
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("~/Resiger.aspx");
}
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/img/新用户注册.png"
onclick="ImageButton2_Click" />
设置属性:validationGroup
------------------------------------------------------------
10.验证文本框TextBox是否为空
1.使用工具箱控件 RequiredFieldValidator
2.设置属性ControToValidate 设置为你想验证的文本框
3.将验证字的颜色设置为红色 ,把ForeColor属性设置为red
-------------------------------------------------------------------------------
11.3秒后页面跳转
<meta http-equiv="Refresh" content="3;URL=http://www.163.com" />
<script type="text/javascript">
var the_timeout; the_timeout = setTimeout("Refresh();", 3000);
function Refresh() { window.location.href = "main.aspx"; }
</script>
----------------------------
12.实现默认情况为为本框(用户名/邮箱),当为本框为空光标移动到别的地方时仍显示(用户名/邮箱)
<script type="text/javascript">
function onfocus1() {
document.getElementById("Text1").value = "";
}
function onfocus2() {
if (document.getElementById("Text1").value =="") {
document.getElementById("Text1").value = "用户名/邮箱";
}
}
</script>
<input runat="server" id="Text1" type="text" value="用户名/邮箱" onfocus="onfocus1();"/>
<input runat="server" id="Text2" type="text" onfocus="onfocus2();"/>
-------------------------------------------
13.web.config里连接数据库
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细消息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="conStr" connectionString="data source=EJNSWJOZ0JSDS7J;Initial
Catalog=CSDNBoKe;User ID=sa;Password=111111; "/>
</connectionStrings>
</configuration>
混合身份登录:
Data Source=YHB-PC;Initial Catalog=MyTest;Persist Security Info=True;User
ID=sa;Password=yhb@163
windows登录:
Data Source=YHB-PC\SQLSERVER2008;database=csdnnews;integrated security=true
连接SQLExpress
Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated
Security=True;User Instance=True
在td标签中加入属性align="center"(这个是左右居中)valign="middle"(这个是上下居中)
例:
<table>
<tr><td align="center" valign="middle">图片文字居中现实代码</td></tr>
</table>
2.绝对定位
<style type="text/css">
#div3
{
position:absolute;
top:100px;
right:267px;
}
</style>
3.图片去边框
img
{
border:none;}
4.超链接去下滑线
a
{
text-decoration:none;
}
<a href="连接到得页">作业</a>
5.将盒子的边框显示出来
<div id="div2" style="border: 2px solid Red; width:211px; height:563px;">
设置盒子在指定的位置
<div id="hezi" style="border: 1px solid Red;width:800px; height:350px; text-align:center;margin-left:200px;position:relative;top:120px; " >
6.加*并使*变成红色
<span class ="w">*</span>
.w
{
color:Red ;
}
7、设置一个图片按钮
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/zhanglan/zhuze.jpg" />
8.验证码
<td id ="d"><img id="yanzhengma" src="yanzhengma.aspx" onclick="this.src='yanzhengma.aspx?aaa='+new Date()" alt="" />
<a href="javascript:Verify();">看不清楚,换张图片 </a>
</td>
<script type="text/javascript" >
function Verify()
{
document.getElementById("yanzhengma").src = "yanzhengma.aspx?time=" + Math.random();
}
</script>
protected void Page_Load(object sender, EventArgs e)
{
System.Random r = new Random();
string s = Convert.ToString(r.Next(1000, 9999));//验证码数字
string path = Server.MapPath("~/images/zhanglan/1.jpg");
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(path))
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
{
g.DrawString(s, new System.Drawing.Font("宋体", 30), System.Drawing.Brushes.Red, 0, 0);
}
bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Session["index"] = s;
}
----------------------------------------------------
9.图片按钮转向另一个界面
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("~/Resiger.aspx");
}
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/img/新用户注册.png"
onclick="ImageButton2_Click" />
设置属性:validationGroup
------------------------------------------------------------
10.验证文本框TextBox是否为空
1.使用工具箱控件 RequiredFieldValidator
2.设置属性ControToValidate 设置为你想验证的文本框
3.将验证字的颜色设置为红色 ,把ForeColor属性设置为red
-------------------------------------------------------------------------------
11.3秒后页面跳转
<meta http-equiv="Refresh" content="3;URL=http://www.163.com" />
<script type="text/javascript">
var the_timeout; the_timeout = setTimeout("Refresh();", 3000);
function Refresh() { window.location.href = "main.aspx"; }
</script>
----------------------------
12.实现默认情况为为本框(用户名/邮箱),当为本框为空光标移动到别的地方时仍显示(用户名/邮箱)
<script type="text/javascript">
function onfocus1() {
document.getElementById("Text1").value = "";
}
function onfocus2() {
if (document.getElementById("Text1").value =="") {
document.getElementById("Text1").value = "用户名/邮箱";
}
}
</script>
<input runat="server" id="Text1" type="text" value="用户名/邮箱" onfocus="onfocus1();"/>
<input runat="server" id="Text2" type="text" onfocus="onfocus2();"/>
-------------------------------------------
13.web.config里连接数据库
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细消息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="conStr" connectionString="data source=EJNSWJOZ0JSDS7J;Initial
Catalog=CSDNBoKe;User ID=sa;Password=111111; "/>
</connectionStrings>
</configuration>
混合身份登录:
Data Source=YHB-PC;Initial Catalog=MyTest;Persist Security Info=True;User
ID=sa;Password=yhb@163
windows登录:
Data Source=YHB-PC\SQLSERVER2008;database=csdnnews;integrated security=true
连接SQLExpress
Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated
Security=True;User Instance=True
相关文章推荐
- 张孝祥老师交通灯管理系统的学习笔记 在做一件事时,首先要明确要达到什么效果。有目的性。就软件项目来说就是,首先要看的就是项目所提出的项目要求。做项目,不急于写代码,先把问题搞清楚,把要求分
- 发表个asp.net的代码生成工具吧,自己写的,一直在项目中使用的,类似Pet Shop代码格式
- 读别人的项目悟自己的代码
- 第十二周项目1-输入日期,输出是本年的多少天(数组法,老师讲解的,事后自己编了一次)
- 就是一个人写代码做软件项目也建议用版本管理器也要考虑采用异地容灾手段
- [Github] 把自己做完的代码提交(commit以及push)到线上公共项目中
- 【项目经验笔记】为何感觉自己的代码越写越乱?
- wap获取手机号码,今天uc开启云加速,用公司的工具类获取是null,但是另外一个项目可以,应该这个项目的工具旧少了一些代码。。,网上找了 方法自己加可以
- iOS:使用Github托管自己本地的项目代码方式二(客户端方式: Github Desktop)
- [置顶] 整理一些代码__xu_init.js 作为自己项目开发时使用
- 跟着郑平老师做通讯录小项目时学到布局界面底部的控件
- 有用代码收集(不断增加,方便自己找)
- 更新GitHub上自己 Fork 的代码与原作者的项目进度一致
- 使用Github存储自己的项目代码
- 【编程初学者】创建自己的开源项目3-将远程代码仓库下载,并创建本地代码仓库(myeclipse + github)
- 跟着郑平老师做通讯录小项目时学到布局界面底部的控件
- angular+ionic+cordova(实战项目开发中,持续更新自己学到的和遇到的)
- 项目经理自己要写代码吗?
- 自己觉得比较有用的WindowsPhone7 Http异步请求的一段简单代码
- 总结自己最近项目中常用的各种类型转换代码(高人勿喷)