我使用 javascript 来启用禁用文本框并根据选中的单选按钮计算价格。
我遇到的问题是我使用单选按钮的组名来找到正确的文本框,并在计算中使用它的值。当转发器从我的 itemtemplate 创建代码时,它不使用提供的参数来创建名称。
我在项目标签中的名字是:name='<%# DataBinder.Eval(Container.DataItem, "idtag_domain") %>' 它创建的名称是 name="Repeater1$ctl02$textbox" 以及我提供的名称标签. 对于单选按钮,它们的名称变为 Repeater1$ctl01$sverigemotrasism 不仅仅是 sverigemotrasism 有没有办法阻止它创建名称......或者我该如何规避它?
这是我的项目模板
<ItemTemplate>
<asp:RadioButton id="RadioButton1" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>' value="50" Text="Fri tillgång" onclick="calculatePrice();disableTB(this.name);" />
<br />
<asp:RadioButton id="RadioButton2" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>'
Text="En artikel om dagen(30/mån)" value="25" onclick="calculatePrice();disableTB(this.name);" />
<br />
<asp:RadioButton id="RadioButton3" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>' value="0"
Text="Skriv antalet artiklar" onclick="enableTB(this.name, this.checked)" />
<br />
<asp:TextBox ID="textbox" runat="server" name='<%# DataBinder.Eval(Container.DataItem, "idtag_domain") %>' Enabled="false" Width="106px"
onkeyup="calculatePrice()" style="background-color:#eeeeee" ></asp:TextBox>
</ItemTemplate>
我的javascript做到了!找出单击了哪个文本框。
function enableTB(tbname, checked)
{
var textboxen = tbname;
document.getElementById(textboxen).disabled = !checked;
document.getElementById(textboxen).style.background = '#C4F8CC';
}
function disableTB(tbname)
{
var textboxen = tbname + 1;
document.getElementById(textboxen).disabled = true;
document.getElementById(textboxen).style.background = '#eeeeee';
}
不幸的是,这就是我的源代码在转发器创建完所有内容后的样子……转发器数据!
<table>
<input id="Repeater1_RadioButton1_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="50" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton1_0">Fri tillgång</label>
<br />
<input id="Repeater1_RadioButton2_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="25" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton2_0">En artikel om dagen(30/mån)</label>
<br />
<input id="Repeater1_RadioButton3_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="0" onclick="enableTB(this.name, this.checked);" /><label for="Repeater1_RadioButton3_0">Skriv antalet artiklar</label>
<br />
<input name="Repeater1$ctl01$textbox" type="text" id="Repeater1_textbox_0" disabled="disabled" class="aspNetDisabled" onkeyup="calculatePrice()" name="sverigemotrasism" style="width:106px;background-color:#eeeeee" />
<tr>
<td>
</td>
</tr>
<input id="Repeater1_RadioButton1_1" type="radio" name="Repeater1$ctl02$handlaihop" value="50" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton1_1">Fri tillgång</label>
<br />
<input id="Repeater1_RadioButton2_1" type="radio" name="Repeater1$ctl02$handlaihop" value="25" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton2_1">En artikel om dagen(30/mån)</label>
<br />
<input id="Repeater1_RadioButton3_1" type="radio" name="Repeater1$ctl02$handlaihop" value="0" onclick="enableTB(this.name, this.checked);" /><label for="Repeater1_RadioButton3_1">Skriv antalet artiklar</label>
<br />
<input name="Repeater1$ctl02$textbox" type="text" id="Repeater1_textbox_1" disabled="disabled" class="aspNetDisabled" onkeyup="calculatePrice()" name="handlaihop" style="width:106px;background-color:#eeeeee" />