欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)備界面代碼:
復(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)界面效果:

4.另外我們可以通過下面的代碼實(shí)現(xiàn)綁定change事件:
復(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)元素。

相關(guān)文章

最新評(píng)論