网络编程 
首页 > 网络编程 > 浏览文章

ASP.NET jQuery 实例10 动态修改hyperlink的URL值

(编辑:jimmy 日期: 2025/5/15 浏览:3 次 )
1.先准备界面代码:
复制代码 代码如下:
<form id="form1" runat="server">
<div align="left">
<fieldset style="width: 300px; height: 200px;">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="width: 10px">
</td>
<td>
<p>
更新网址:</p>
<asp:RadioButtonList ID="rblUrl" runat="server">
<asp:ListItem Text="新浪" Value="http://www.sina.com.cn"></asp:ListItem>
<asp:ListItem Text="百度" Value="http://www.baidu.com"></asp:ListItem>
<asp:ListItem Text="网易" Value="http://www.163.com"></asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:HyperLink ID="hyperLink" runat="server">点击这儿</asp:HyperLink>
</td>
</tr>
</table>
</fieldset>
</div>
</form>

2.RadioButtonList转换成<table/>,其成员转换为<input type="radio"/>,下面是实现改变URL值的脚本代码:
复制代码 代码如下:
<head runat="server">
<title>Recipe10</title>
<script src="/UploadFiles/2021-04-02/jquery.js"><script type="text/javascript">
$(document).ready(function () {
$("input[type=radio]").bind("change", function () {
$("#<%=hyperLink.ClientID %>").attr("href", $(this).val());
});
});
</script>
</head>

3.实现界面效果:

ASP.NET jQuery 实例10 动态修改hyperlink的URL值

4.另外我们可以通过下面的代码实现绑定change事件:
复制代码 代码如下:
$("input=[type=radio]").live("change", function(){
$("a").attr("href", $(this).val());
});

5.live()和bind()函数的区别:
live()函数可以附加事件到现在的和将来的页面元素上。然而,bind()函数只能把事件附加到已经加载过的页面元素上。
也就是说bind()适合页面静态元素而live()适合页面静态和动态元素。
上一篇:ASP.NET jQuery 实例11 通过使用jQuery validation插件简单实现用户登录页面验证功能
下一篇:ASP.NET jQuery 实例9  通过控件hyperlink实现返回顶部效果
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap