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.