网页里有一个下拉列表和一个OK按钮,要求点击后下拉列表变成单选按钮。( 下拉列表的值给了单选按钮 )代码如下 :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
function btnOKClientClick() {
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Height="23px" Width="100px">
<asp:ListItem >北京</asp:ListItem>
<asp:ListItem >上海</asp:ListItem>
<asp:ListItem >广州</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnOk" runat="server" Height="19px" Text="OK" Width="48px" OnClientClick="btnOKClientClick()"/>
<asp:RadioButton ID="RadioButton1" runat="server" />
</div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
function btnOKClientClick() {
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Height="23px" Width="100px">
<asp:ListItem >北京</asp:ListItem>
<asp:ListItem >上海</asp:ListItem>
<asp:ListItem >广州</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnOk" runat="server" Height="19px" Text="OK" Width="48px" OnClientClick="btnOKClientClick()"/>
<asp:RadioButton ID="RadioButton1" runat="server" />
</div>
</form>
</body>
</html>
function btnOKClientClick() {
var selectValue = document.getElementById("DropDownList1").value;
document.getElementById("RadioButton1").value = selectValue;
}
<head id="Head1" runat="server">
<title></title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function btnOKClientClick() {
var rdo = "";
$("#DropDownList1 option").each(function(){
rdo+= "<input type='radio' value='"+$(this).val()+"' name='city' />"+$(this).text();
});
$("#btnOk").after(rdo);
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" Height="23px" Width="100px">
<asp:ListItem Value="bj" >北京</asp:ListItem>
<asp:ListItem Value="sh" >上海</asp:ListItem>
<asp:ListItem Value="gz" >广州</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnOk" runat="server" Height="19px" Text="OK" Width="48px" OnClientClick="return btnOKClientClick()"/>
</div>
</form>
</body>
</html>是不是要这样 。
有两个疑问:1.能否把 DropDownList 隐藏,只显示radio
2.$("#btnOk").after(rdo); 这段的能否给点解释,after起到什么作用。
2.是在button后面添加一个radiobutton元素'rdo'
$("#btnOk").after(rdo); 在#btnOk(就是那个按钮) 后面添加元素 。 rdo是拼的字符串 。