ASP. NET jQuery instance 10 dynamically modify the URL value of hyperlink

Source: Internet
Author: User

1. Prepare the interface code first:
Copy codeThe Code is as follows:
<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>
URL updated: </p>
<Asp: RadioButtonList ID = "rblUrl" runat = "server">
<Asp: ListItem Text = "Sina" Value = "http://www.sina.com.cn"> </asp: ListItem>
<Asp: ListItem Text = "Baidu" Value = "http://www.baidu.com"> </asp: ListItem>
<Asp: ListItem Text = "Netease" Value = "http://www.163.com"> </asp: ListItem>
</Asp: RadioButtonList>
<Br/>
<Asp: HyperLink ID = "hyperLink" runat = "server"> click here </asp: HyperLink>
</Td>
</Tr>
</Table>
</Fieldset>
</Div>
</Form>

2. RadioButtonList is converted to <table/>, and its members are converted to <input type = "radio"/>. The script code to change the URL value is as follows:
Copy codeThe Code is as follows:
<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. Implement the interface effect:

4. In addition, we can bind the change event through the following code:
Copy codeThe Code is as follows:
$ ("Input = [type = radio]"). live ("change", function (){
$ ("A"). attr ("href", $ (this). val ());
});

5. Differences between live () and bind () functions:
The live () function can append events to current and future page elements. However, the bind () function can only attach events to the page elements that have been loaded.
That is to say, bind () is suitable for static page elements while live () is suitable for static and dynamic page elements.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.