|
■No96279 (simano さん) に返信
RadioButton.GroupName の設定の問題では?
以下のコードでやってみましたが、少なくと見かけは両方同じように動きます。
.aspx.cs
--------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm13 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RadioButton1.InputAttributes.Add("class", "group_btn");
RadioButton2.InputAttributes.Add("class", "group_btn");
}
}
}
.aspx
-----
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm13.aspx.cs"
Inherits="WebApplication1.WebForm13" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.group_btn {
display:none;
}
.group_btn:active + .group_btn_label {
color: blue;
}
.group_btn:checked + .group_btn_label {
color: blue;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h3>元のhtml</h3>
<div>
<input id="btn_id_1" class="group_btn" name="group_btn" type="radio" />
<label for="btn_id_1" class="group_btn_label">一番目の選択肢</label>
</div>
<div>
<input id="btn_id_2" class="group_btn" name="group_btn" type="radio" />
<label for="btn_id_2" class="group_btn_label">二番目の選択肢</label>
</div>
<h3>ASP.NET</h3>
<div>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="aspnet_btn" />
<label for="RadioButton1" class="group_btn_label">一番目の選択肢</label>
</div>
<div>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="aspnet_btn" />
<label for="RadioButton2" class="group_btn_label">二番目の選択肢</label>
</div>
</form>
</body>
</html>
html
----
<h3>元のhtml</h3>
<div>
<input id="btn_id_1" class="group_btn" name="group_btn" type="radio" />
<label for="btn_id_1" class="group_btn_label">一番目の選択肢</label>
</div>
<div>
<input id="btn_id_2" class="group_btn" name="group_btn" type="radio" />
<label for="btn_id_2" class="group_btn_label">二番目の選択肢</label>
</div>
<h3>ASP.NET</h3>
<div>
<input id="RadioButton1" type="radio" name="aspnet_btn" value="RadioButton1" class="group_btn" />
<label for="RadioButton1" class="group_btn_label">一番目の選択肢</label>
</div>
<div>
<input id="RadioButton2" type="radio" name="aspnet_btn" value="RadioButton2" class="group_btn" />
<label for="RadioButton2" class="group_btn_label">二番目の選択肢</label>
</div>
|