【问题标题】:create radio button from code behind but with an onclick?从后面的代码创建单选按钮,但有一个 onclick?
【发布时间】:2015-09-16 02:50:00
【问题描述】:

我在前端有一张桌子......

<table>
<tr>
<td style="padding-right:8px">
<input id="mmapMS" type="radio" name="Layers" value="mmapMS" onclick="addLayer()" style="display:none"/>
<label class="Layer-cc mMS" for="mMS" data-tip="mMS"></label>
</td>
</tr>
</table>

需要将单选按钮更改为从后端运行...到目前为止一切都很好(如下),但是当我单击单选按钮时我无法找到如何调用 js 函数??...onclick=" addLayer()" 任何想法...谢谢

                TableRow row = new TableRow();
                TableCell cell = new TableCell();

                HtmlInputRadioButton btn = new HtmlInputRadioButton();
                btn.ID = mapGenieImage;
                btn.Value = mapGenieImage;
                btn.Visible = false;
                cell.Controls.Add(btn);

                Label lb = new Label();   
                lb.CssClass = "Layer-cc " + mapImage;
                cell.Controls.Add(lb);

                row.Cells.Add(cell);
                table.Rows.Add(row);

【问题讨论】:

    标签: javascript c# jquery asp.net


    【解决方案1】:
    HtmlInputRadioButton btn = new HtmlInputRadioButton();
    btn.ID = mapGenieImage;
    btn.Value = mapGenieImage;
    btn.Visible = false;
    btn.attributes.add("onclick","addLayer()")  '<-- Add me.
    cell.Controls.Add(btn);
    

    创建控件时,添加一个 onClick 属性,该属性调用您的 addLayer() 脚本。

    【讨论】:

    • 感谢您发布此问题的答案!在 Stack Overflow 上不鼓励仅使用代码的答案,因为原始发布者(或未来的读者)可能难以理解它们背后的逻辑。请编辑您的问题并包含对您的代码的解释,以便其他人可以从您的回答中受益。谢谢!
    猜你喜欢
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    相关资源
    最近更新 更多