ASP.NET jQuery 食譜10 (動(dòng)態(tài)修改hyperlink的UR
系統(tǒng)
2875 0
這節(jié)我們來(lái)看下如何實(shí)現(xiàn)通過(guò)選擇RadioButtonList值動(dòng)態(tài)改變hyperlink控件的URL值,并簡(jiǎn)要介紹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)界面效果:
?
4.另外我們可以通過(guò)下面的代碼實(shí)現(xiàn)綁定change事件:
$("input=[type=radio]").live("change", function(){
? $("a").attr("href", $(this).val());
});
5.live()和bind()函數(shù)的區(qū)別:
live()函數(shù)可以附加事件到現(xiàn)在的和將來(lái)的頁(yè)面元素上。然而,bind()函數(shù)只能把事件附加到已經(jīng)加載過(guò)的頁(yè)面元素上。
也就是說(shuō)bind()適合頁(yè)面靜態(tài)元素而live()適合頁(yè)面靜態(tài)和動(dòng)態(tài)元素。
?
ASP.NET jQuery 食譜10 (動(dòng)態(tài)修改hyperlink的URL值)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元