html - 如何将我的 HTML 标签与 ASP.Net 单选按钮相关联?
问题描述
我有一个已将图像链接到的 HTML 标签,因此当您单击图像时,图像会突出显示并选择单选按钮(在图像下方)。我正在尝试将单选按钮转换为 ASP 单选按钮,以便我可以在后面的代码中引用它,但无法确定如何关联标签。
我认为这可能是因为它是 ASP 的 HTML,它可能不起作用,所以我尝试使用 ASP 标签,但据我所知,标签不允许您在其中包含图像。
这就是它的工作方式:
<div class="form-holder form-holder-2">
<input type="radio" class="radio" name="radio1" id="p1" value="p1">
<label class="plan-icon plan-1-label" for="p1">
<img src="images/frmMM1.png" alt="p1">
</label>
<div class="plan-total">
<span class="plan-title">Managing your money</span>
<p class="plan-text">Placeholder</p>
</div>
</div>
这是它现在的样子:
<div class="form-holder form-holder-2">
<asp:RadioButton ID="rbMM1" AssociatedControlID="rbMM1" ClientIDMode="Static" runat="server" CssClass="radio" GroupName="rbMM" Checked="true" />
<label class="plan-icon plan-1-label" for="rbMM1" >
<img src="images/frmMM1.png" alt="p1">
</label>
<div class="plan-total">
<span class="plan-title">Managing your money</span>
<p class="plan-text">Placeholder</p>
</div>
</div>
运行应用程序时,最初的一切看起来都一样,但单选按钮不可点击(来自图像)。有没有更好的方法可以实现上述目标?
解决方案
请尝试runat="server"
为您的标签添加属性。
<label class="plan-icon plan-1-label" for="rbMM1" runat="server">
<img src="images/frmMM1.png" alt="p1">
</label>
这样我就可以在类后面的代码中使用该标签的值。让我知道它是否适合您。
推荐阅读
- ios - Websocket 和 WebRTC 在 iOS Swift 5 中处于后台时断开连接
- reactjs - 如何使用 ionic v4 添加自定义 webpack 配置并做出反应?
- c# - 无法加载文件或程序集......但不是一开始?
- python - 在 Python 或 C++ 中删除 K -Means 聚类/的背景掩码
- python - 用另一个字符替换一个字符序列
- javascript - React 和 Material UI:如何仅扩展一张卡片
- python - 原始 f 字符串 SyntaxError
- hazelcast - Hazelcast mancenter 分区组监控
- r - 在 R 中为主题建模预处理文本时得到奇怪的字符
- c# - 如何在 WPF 中取消被阻止的任务