</div> </form> </body> </html>using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;public partial class Default3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.ImageButton1.Attributes.Add("onmouseover", "change()"); this.ImageButton2.Attributes.Add("onmouseover", "reset()");
<head runat="server">
<title>无标题页</title>
<SCRIPT language="javascript">
function Display(sid)
{ if (sid.style.display == "none")
{
sid.style.display="";
}else{
sid.style.display="none";
}
}
</SCRIPT>
</head>
<body>
<input type=button value="显示与隐藏" onclick="Display(form1)" />
<form id="form1" runat="server">
<div>
div div this is div .........
</div>
<table>
<tr>
<td><div>+</div></td>
<td>45454545</td>
</tr>
</table>
</form>
</body>
</html>
其实最主要的就是设置div1.style.display <html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<SCRIPT language="javascript">
function Display(sid)
{ if (document.all.div1.style.display == "none")
{
document.all.div1.style.display="block";
}else{
document.all.div1.style.display="none";
}
}
</SCRIPT>
</head>
<body>
<input type=button value="显示与隐藏" onclick="Display(form1)" />
<form id="form1" runat="server">
<div id="div1">
sdfasdfsadfsdfsdfsdafsdfsadf
</div>
<table>
<tr>
<td><div>+</div></td>
<td>45454545</td>
</tr>
</table>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>无标题页 </title> <script language="javascript">
function display(id)
{
var div=document.getElementById(id);
div.style.display="none";
}
function show(id)
{
var div=document.getElementById(id);
div.style.display="";
}
</script></head>
<body>
<form id="form1" runat="server">
<input type="button" value="隐藏" onmousemove="display('div1');" onmouseout ="show('div1');" />
<div id="div1">
<strong>呵呵...
<br />
我胡汉三又回来了. </strong>
</div>
</form>
</body>
</html>
{
protected void Page_Load(object sender, EventArgs e)
{
this.ImageButton1.Attributes.Add("onmouseover", "change()");
this.ImageButton2.Attributes.Add("onmouseover", "reset()");
}
}
//HTML里面
<script type="text/javascript">
function change()
{
document.form1.all["ImageButton1"].src="images/3223.bmp";//改变图片地址
document.form1.all["ImageButton2"].src="images/3223.bmp"; //改变图片地址
document.getElementById("HyperLink1").innerText = "aaa"; //改变text文本值
document.getElementById("ImageButton3").style.display="none";//隐藏控件
}
function reset()
{
document.form1.all["ImageButton1"].src="images/333.bmp";//改变图片地址
document.form1.all["ImageButton2"].src="images/333.bmp"; //改变图片地址
document.getElementById("HyperLink1").innerText = "aaa"; //改变text文本值
document.getElementById("ImageButton3").style.display="block";//隐藏控件
}
</script>
我移动到ImageButton1上事件能触发 为什么移动到ImageButton2上面 ImageButton2对应的事件不会被触发
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DIVControl._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function view()
{
document.getElementById("myDiv").style.visibility="visible";
}
function hide()
{
document.getElementById("myDiv").style.visibility="hidden";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<asp:Button ID="ControlDiv" name="ControlDiv" runat="server" Text="把鼠标移上来看看" onmouseover="view();" onmouseout="hide();" />
<div id="myDiv" style="background-color:Gray; width:128px; height:56px; text-align: center; visibility:hidden" >你好!我是隐藏的DIV
</div>
</center>
</div>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
</head><script type="text/javascript">
function change()
{
document.form1.all["ImageButton1"].src="images/3223.bmp";//改变图片地址
document.form1.all["ImageButton2"].src="images/3223.bmp"; //改变图片地址
document.getElementById("HyperLink1").innerText = "aaa"; //改变text文本值
document.getElementById("ImageButton3").style.display="none";//隐藏控件
}
function reset()
{ alert("2");
document.form1.all["ImageButton1"].src="images/333.bmp";//改变图片地址
document.form1.all["ImageButton2"].src="images/333.bmp"; //改变图片地址
document.getElementById("HyperLink1").innerText = "aaa"; //改变text文本值
document.getElementById("ImageButton3").style.display="block";//隐藏控件
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:ImageButton ID="ImageButton1" runat="server" Height="38px" Style="z-index: 100;
left: 13px; position: absolute; top: 17px" Width="81px" />
<asp:HyperLink ID="HyperLink1" runat="server" Height="30px" NavigateUrl="~/Default.aspx"
Style="z-index: 101; left: 16px; position: absolute; top: 80px" Width="154px">asasa</asp:HyperLink>
<asp:ImageButton ID="ImageButton2" runat="server" Height="35px" Style="z-index: 102;
left: 137px; position: absolute; top: 15px" Width="83px" />
<asp:ImageButton ID="ImageButton3" runat="server" Height="75px" Style="z-index: 104;
left: 166px; position: absolute; top: 110px" Width="102px" />
</div>
</form>
</body>
</html>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.ImageButton1.Attributes.Add("onmouseover", "change()");
this.ImageButton2.Attributes.Add("onmouseover", "reset()");
}
}为什么只有ImageButton1有触发,ImageButton2触发不了
不在后台注册试试。也许是在ImageButton1触发之后ImageButton2改变了
document.all.div1.style.display="none"; //隐藏////完整的HTML代码如下
<script>
function ShowDiv()
{
var div_obj=document.getElementById("your_div_id");
div_obj.style.display="block";
}
</script>
<div id="your_div_id" style="display:none;">This is a message!</div>
<input type="button" onmouseover="ShowDiv();" value="显示层" />
function HideDiv()
{
var div_obj=document.getElementById("your_div_id");
div_obj.style.display="none";
}
</script>
<div id="your_div_id" style="display:block;">This is a message!</div>
<input type="button" onmouseover="HideDiv();" value="隐藏" />
关键就是DIV的style设置,你可以用javascript对其进行任何style属性的设置,甚至可以移动div
还有就是常用的HTML控件事件,如本例的onmouseover做BS开发的,HTML一定要花点心思了解了解咯,还有JavaScript也非常重要。
建议看看 http://www.w3school.com.cn/tags/html_ref_eventattributes.asp
if(a=="images/xinyongdangan.jpg")
{
//我写的代码}HTML 里面 格式不对,正确写法是什么?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????