Plzz有人告诉我下面代码中的问题是什么......因为第一个函数(changeME )正在工作但 2ND函数(inputName ) )不工作....变量存在一些问题吗?正如我在asp.net上的新篇章一样,帮助我解决了一些我可能会遗漏的基本概念。
`PROJECT
<input type="radio" name="portal" id="radio1" onclick="changeMe(this);"/> <input type="text" name="textprojectOff" id="text1" value="Project Name" onclick="changeMe(this);"/>
<script type="text/javascript" >
function changeMe(inField) {
var fieldId = inField.id;
var type = fieldId.substring(0, 4);
if (type == 'text') {
var name = fieldId.substring(4);
var radioButton = document.getElementById("radio" + name);
radioButton.checked = true;
} else {
var name = fieldId.substring(5);
var textField = document.getElementById("text" + name);
textField.focus();
}
}
</script>
NON-PROJECT<input type="radio" id="radio2" name="portal" onclick="inputName(this)"/> <input type="text" name="textnonprojectOff" id="text2" value="Departement" onclick="inputName(this);"/>
<script type="text/javascript">
function inputName(inDepartment){
var departmentId=inDepartment.id;
var type= departmentId.substring(0,4);
if (type== 'text'){
var name= inDepartment.substring(4);
var radioButton=document.getElementById("radio"+ name);
radioButton.checked=true;
}
else{
var name=inDepartment.substring(5);
var textfield=document.getElementById("text"+name);
textfield.focus();
}
</script>
protected void RadioButton2_Checked(object sender, EventArgs e)
{
if (RadioButton2.Checked)
{
TextBox11.Visible = true;
}
else
{
TextBox11.Visible = false;
TextBox11.Text = string.Empty;
}
}
protected void RadioButton3_Checked(object sender, EventArgs e)
{
if (RadioButton3.Checked)
{
TextBox12.Visible = true;
}
else
{
TextBox12.Visible = false;
TextBox12.Text = string.Empty;
}
}
任何人都可以根据我之前的要求修改此代码,因为我的AIM与之前相同,但现在我使用了代码隐藏...但它无法正常工作..
请仔细阅读前面答案中给出的小提琴,并相应地修改此代码。
答案 0 :(得分:2)
选中 Fiddle
function inputName(inDepartment){
var departmentId=inDepartment.id;
var type= departmentId.substring(0,4);
if (type== 'text'){
var name= departmentId.substring(4);
var radioButton=document.getElementById("radio"+ name);
radioButton.checked=true;
}
else{
var name=departmentId.substring(5);
var textfield=document.getElementById("text"+name);
textfield.focus();
}
}
var name= departmentId.substring(4);
而非var name= inDepartment.substring(4);