<input type='button' onclick='plus()' value='点击我'/><span id='num'>1</span>
<script>
function plus()
{
var n=documentgetElementById("num");
ninnerHTML=parseInt(ninnerHTML)+1;
}
</script>
参考这段代码
母版页
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPagemastercs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" "http://wwww3org/TR/xhtml1/DTD/xhtml1-transitionaldtd">
<html xmlns="http://wwww3org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="用户名"></asp:Label>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
内容页后台代码
protected void Page_Load(object sender, EventArgs e)
{
string str = (MasterFindControl("Label1") as Label)Text;
//获得母版页ID为Label1的控件的文本属性即你LABEL控件中的用户名。
ResponseWrite("<script>alert(" + str + ")</script>");
//此弹出对话框用来测试获取的内容,确认获得的内容是否是母版页上LABEL控件上的用户名。
}
html的话,用JS 使用value属性赋值。IE8下 通过测试。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" " http://wwww3org/TR/xhtml1/DTD/xhtml1-transitionaldtd"><html xmlns=" http://wwww3org/1999/xhtml">
<head>
<title>无标题页</title>
<script type="text/javascript">
var cost = 0;function add(objid)
{
documentgetElementById(objid)value++;
}
function Less(objid)
{
documentgetElementById(objid)value--;
}</script>
</head>
<body> <p>
<input id="v1" type="text" value="1" /><input id="Button1" type="button"
value="+" onclick="add('v1')" /><input id="Button2" type="button" value="-" onclick="Less('v1')"/></p>
<p>
<input id="v2" type="text" value="10" /><input id="Button3" type="button"
value="+" onclick="add('v2')"/><input id="Button4" type="button" value="-" onclick="Less('v2')"/></p></body>
</html>
欢迎分享,转载请注明来源:品搜搜测评网