ASP.NET jQuery 實(shí)例10 動(dòng)態(tài)修改hyperlink的URL值
更新時(shí)間:2012年02月03日 17:01:33 作者:
這節(jié)我們來看下如何實(shí)現(xiàn)通過選擇RadioButtonList值動(dòng)態(tài)改變hyperlink控件的URL值,并簡要介紹bind和live方法的區(qū)別
1.先準(zhǔn)備界面代碼:
<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>
更新網(wǎng)址:</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="網(wǎng)易" Value="http://www.163.com"></asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:HyperLink ID="hyperLink" runat="server">點(diǎn)擊這兒</asp:HyperLink>
</td>
</tr>
</table>
</fieldset>
</div>
</form>
2.RadioButtonList轉(zhuǎn)換成<table/>,其成員轉(zhuǎn)換為<input type="radio"/>,下面是實(shí)現(xiàn)改變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.實(shí)現(xiàn)界面效果:
$("input=[type=radio]").live("change", function(){
$("a").attr("href", $(this).val());
});
5.live()和bind()函數(shù)的區(qū)別:
live()函數(shù)可以附加事件到現(xiàn)在的和將來的頁面元素上。然而,bind()函數(shù)只能把事件附加到已經(jīng)加載過的頁面元素上。
也就是說bind()適合頁面靜態(tài)元素而live()適合頁面靜態(tài)和動(dòng)態(tài)元素。
復(fù)制代碼 代碼如下:
<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>
更新網(wǎng)址:</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="網(wǎng)易" Value="http://www.163.com"></asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:HyperLink ID="hyperLink" runat="server">點(diǎn)擊這兒</asp:HyperLink>
</td>
</tr>
</table>
</fieldset>
</div>
</form>
2.RadioButtonList轉(zhuǎn)換成<table/>,其成員轉(zhuǎn)換為<input type="radio"/>,下面是實(shí)現(xiàn)改變URL值的腳本代碼:
復(fù)制代碼 代碼如下:
<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.實(shí)現(xiàn)界面效果:
復(fù)制代碼 代碼如下:
$("input=[type=radio]").live("change", function(){
$("a").attr("href", $(this).val());
});
5.live()和bind()函數(shù)的區(qū)別:
live()函數(shù)可以附加事件到現(xiàn)在的和將來的頁面元素上。然而,bind()函數(shù)只能把事件附加到已經(jīng)加載過的頁面元素上。
也就是說bind()適合頁面靜態(tài)元素而live()適合頁面靜態(tài)和動(dòng)態(tài)元素。
您可能感興趣的文章:
- jQuery在頁面加載時(shí)動(dòng)態(tài)修改圖片尺寸的方法
- jQuery動(dòng)態(tài)修改超鏈接地址的方法
- jQuery動(dòng)態(tài)改變圖片顯示大小(修改版)的實(shí)現(xiàn)思路及代碼
- jquery實(shí)現(xiàn)實(shí)時(shí)改變網(wǎng)頁字體大小、字體背景色和顏色的方法
- jQuery實(shí)現(xiàn)自動(dòng)調(diào)整字體大小的方法
- jQuery實(shí)現(xiàn)切換字體大小的方法
- jQuery之字體大小的設(shè)置方法
- jquery更換文章內(nèi)容與改變字體大小代碼
- JQuery 改變頁面字體大小的實(shí)現(xiàn)代碼(實(shí)時(shí)改變網(wǎng)頁字體大小)
- jQuery動(dòng)態(tài)修改字體大小的方法【測試可用】
相關(guān)文章
Jquery 實(shí)現(xiàn)checkbox全選方法
本文主要向大家展示了一段使用jQuery實(shí)現(xiàn)checkbox全選的方法,以及編寫此方法的背景和過程,非常詳細(xì),這里推薦給小伙伴們。2015-01-01jQuery實(shí)現(xiàn)頁面滾動(dòng)時(shí)智能浮動(dòng)定位
本文主要介紹了jQuery實(shí)現(xiàn)頁面滾動(dòng)時(shí)智能浮動(dòng)定位的方法。附上完整代碼,具有一定的參考價(jià)值,下面跟著小編一起來看下吧2017-01-01jquery動(dòng)態(tài)分頁效果堪比時(shí)光網(wǎng)
剛剛弄好了一個(gè)jquery動(dòng)態(tài)分頁效果,拿出來與大家分享,效果與時(shí)光網(wǎng)的差不多2014-09-09jquery獲取div寬度的實(shí)現(xiàn)思路與代碼
DIV的width寬度如何獲取呢?接下來介紹使用jquery獲取DIV的width寬度,感興趣的朋友可以了解下的2013-01-01jQuery實(shí)現(xiàn)獲取隱藏div高度的方法示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)獲取隱藏div高度的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了jQuery針對頁面元素屬性操作的相關(guān)技巧,需要的朋友可以參考下2017-02-02