作家
登录

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

作者: 来源:www.28hudong.com 2013-03-30 00:34:27 阅读 我要评论

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="Scripts/jquery.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $("input[type=radio]").bind("change", function () { $("#<%=hyperLink.ClientID %>").attr("href", $(this).val()); }); }); </script> </head> 3.实现界面效果: 4.另外我们可以通过下面的代码实现绑定change事件: 复制代码 代码如下: $("input=[type=radio]").live("change", function(){ $("a").attr("href", $(this).val()); }); 5.live()和bind()函数的区别: live()函数可以附加事件到现在的和将来的页面元素上。然而,bind()函数只能把事件附加到已经加载过的页面元素上。 也就是说bind()适合页面静态元素而live()适合页面静态和动态元素。

  推荐阅读

  8款非常棒的响应式jQuery 幻灯片插件推荐

这篇文章收集了8款优秀的响应式 jQuery 幻灯片插件,它们能够非常容易的集成到 Web 项目中。响应式(Responsive)设计的目标是要让产品界面能够响应用户的行为,根据不同终端设备自动调整尺寸,带给用户良好的使用>>>详细阅读


本文标题:ASP.NET jQuery 实例10 动态修改hyperlink的URL值

地址:http://www.17bianji.com/kaifa2/JS/23685.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)