zoukankan
html css js c++ java
脚本与后端数据传递小技巧
表单中input标签为文本框,其提供了一个隐藏域,可以用来保存输入的内容,像div这样的标签,即使使用脚本使其内部值发生了变化,但是无法保存值,所以隐藏域的作用就提升了.可以来测试下.
<%
@ Page Language
=
"
C#
"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
script
runat
="server"
>
protected
void
Button2_Click(object sender, EventArgs e)
{
Label1.Text
=
HiddenField1.Value
+
TextBox1.Text
+
aaa.InnerHtml;
}
</
script
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
无标题页
</
title
>
<
script
language
="javascript"
type
="text/javascript"
>
//
<!CDATA[
function
aa()
{
document.getElementById(
"
HiddenField1
"
).value
=
"
a
"
;
document.getElementById(
"
TextBox1
"
).value
=
"
b
"
;
document.getElementById(
"
aaa
"
).innerHTML
=
"
c
"
;
}
//
]]>
</
script
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
input
id
="Hidden1"
type
="hidden"
/>
<
asp:HiddenField
ID
="HiddenField1"
runat
="server"
/>
<
asp:TextBox
ID
="TextBox1"
runat
="server"
></
asp:TextBox
>
<
div
id
="aaa"
runat
="server"
></
div
>
<
br
/>
<
input
id
="Button1"
type
="button"
value
="button"
onclick
="aa()"
/>
<
asp:Label
ID
="Label1"
runat
="server"
Text
="Label"
></
asp:Label
>
<
asp:Button
ID
="Button2"
runat
="server"
OnClick
="Button2_Click"
Text
="Button"
/>
</
form
>
</
body
>
</
html
>
这样的使用方法在控件中非常常用,AjaxControlToolkit的基类ExtenderControlBase也使用了这样了方法,其提供了ClientState属性可以获取隐藏域的值.方便了前台和后台的交互
查看全文
相关阅读:
13/6/21 Hella Intern Interview
【ToReadList】六种姿势拿下连续子序列最大和问题,附伪代码(以HDU 1003 1231为例)(转载)
【算法】[leetcode] permutations的讨论(转载)
【算法】leetcode之 Palindrome Partitioning I&II(转载)
【C++】从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法
【C++】STL :栈
【算法】逆波兰表达式
【C++】STL,vector容器操作
【LINUX】降级安装低版本GCC,G++
【NS2】在linux下安装低版本GGC
原文地址:https://www.cnblogs.com/Clingingboy/p/784370.html
最新文章
GDI+学习---2.GDI+编程模式及组成类
GDI+学习---1.初识GDI+
推荐使用string
C++11 线程并发
随机数
lambda、pair、智能指针及时间函数
现代C++简单介绍
CMFCToolBar、CMFCStatusBar
EVC编程点滴四
VS2005 学习记录
热门文章
【转】C 语言中的指针和内存泄漏
【转】C语言:内存使用
C语言:动态内存会被自动释放吗?杜绝“野指针”
【转】C语言:指针,C的灵魂
工具介绍
LINK : fatal error LNK1104: cannot open file 'mfcs42d.lib'
EVC4 自制SDK与VS2005 冲突
VS2005 学习记录2-窗体
躲开Xilinx官网龟速的下载器
如何在LabWIndows/CVI中调用LabVIEW DLL
Copyright © 2011-2022 走看看