我有一个JavaScript函数,需要将它添加到一些动态创建的单选按钮onclick后面的代码。将javascript onclick添加到单选按钮INPUT标记
我试过 - newRadioSelect.Attributes.Add(“点击数”,“JavaScript的:切换(本);”)
上面的代码把它添加到的单选按钮造成的,任何想法跨度标签如何获得单选按钮的输入标签?
感谢
J.
我有一个JavaScript函数,需要将它添加到一些动态创建的单选按钮onclick后面的代码。将javascript onclick添加到单选按钮INPUT标记
我试过 - newRadioSelect.Attributes.Add(“点击数”,“JavaScript的:切换(本);”)
上面的代码把它添加到的单选按钮造成的,任何想法跨度标签如何获得单选按钮的输入标签?
感谢
J.
像公共汽车了一下,没有适用年龄,然后在2一遇的属性添加到您的动态RadioButton
。
我想出了一个方法来做到这一点,并让它工作,然后我从其他地方收到了答案,所以我想我会把它们放在这里。
我的版本(不是最好的)
Dim newRadioYes As New RadioButton
newRadioYes.Text = "Yes"
newRadioYes.ID = "c_" & childID & "_school_selected_0"
newRadioYes.Attributes.Add("onclick", "javascript:toggle(this, " & childID & ");")
newRadioYes.Attributes.Add("value", "Yes")
newRadioYes.GroupName = "c_" & childID & "_school_selected"
Dim newRadioNo As New RadioButton
newRadioNo.Text = "No"
newRadioNo.ID = "c_" & childID & "_school_selected_1"
newRadioNo.Attributes.Add("onclick", "javascript:toggle(this, " & childID & ");")
newRadioNo.Attributes.Add("value", "No")
newRadioNo.GroupName = "c_" & childID & "_school_selected"
更好的版本
Dim newRadioSelect As New RadioButtonList
newRadioSelect.RepeatDirection = RepeatDirection.Horizontal
newRadioSelect.RepeatLayout = RepeatLayout.Flow
newRadioSelect.Items.Add("Yes")
newRadioSelect.Items.Add("No")
newRadioSelect.Items(0).Attributes.Add("onclick", "javascript:toggle(this);")
newRadioSelect.Items(1).Attributes.Add("onclick", "javascript:toggle(this);")
感谢那些谁帮助。
只是用这个javascript函数,你并不需要明确将其添加到标签。
http://www.mediaevent.de/javascript/event_listener.html
newRadioSelect.addEventListener("click", myFunction, false);
function myFunction(event){
toggle(event.target);
}
可以以这种方式
rb.Attributes["onClick"] = "javascript:alert('Hi');";
是不是像我在上面,但在C#?它将其添加到.net RadioButtonList创建的标记中,我需要将它附加到标记。 – JBoom 2011-05-10 11:30:55
以及它被连接到输入标签。检查viewsource,你会看到它。 – V4Vendetta 2011-05-10 11:36:32
另外,如上所示,您的代码中存在拼写错误 – V4Vendetta 2011-05-10 11:37:17
对不起,我不认为我解释得很好。我正在使用asp.net并试图从代码后面添加它。 – JBoom 2011-05-10 09:32:40
哦,对不起,我刚刚看到的代码和thougt它是JavaScript :) – Fender 2011-05-10 10:17:55