zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Jquery从头学起第四讲jquery入门教程

jQuery入门教程 第四 从头
2023-06-13 09:14:23 时间
今天主要讲的控件是radio,select,input,Label,Literal。这边服务器控件讲的比较少,主要是因为服务器控件一来可以在后台赋值,其次服务器控件在解析后也是也是html控件
在平时写程序的时候,给radio赋值最头痛了。今天把这些控件的赋值做成DEMO,跟大家一起分享。
复制代码代码如下:

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Jquery4.aspx.cs"Inherits="JQuery_1.Jquery4"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>JQuery给控件赋值www.54talk.cn</title>
<scripttype="text/javascript"src="JS/jquery-1.3.2.min.js"></script>
<scripttype="text/javascript">
$(document).ready(function(){
alert("aa");
varv1="2";
varv2="2";
varv3="abc";
varv4="lab";
varv5="lit";
$("input[name="rdo"][value=1]").attr("checked",true);
//这里的input后面不能有空格,如果有空格,则不能赋值
//value后面不用引号
$("#s1").val(v2);
$("#ipt").val(v3);

$("#lab1").text(v4);
//这里必须是html或者text如果用val()这不能显示任何内容
$("#lit1").html(v5);
//这里不能显示任何东西,因为Literal在客户端不会解析成任何标签
//这里特意拿出来就是为了提醒大家
//<span></span>标签和Label是一样的
});
</script>
</head>
<body>
<formid="form1"runat="server">
<div>
<!--radio-->
a<inputtype="radio"name="rdo"id="r1"value="0"/>
b<inputtype="radio"name="rdo"id="r2"value="1"/>
c<inputtype="radio"name="rdo"id="r3"value="2"/>
<!--select-->
<selectid="s1">
<optionvalue="0">11</option>
<optionvalue="1"selected="selected">22</option>
<optionvalue="2">33</option>
<optionvalue="3">44</option>
</select>
<!--input-->
<inputtype="text"id="ipt"/>
<asp:LabelID="lab1"runat="server"></asp:Label>
<asp:LiteralID="lit1"runat="server"></asp:Literal>
</div>
</form>
</body>
</html>