在Coldfusion中,程序person1.cfm有这样的代码:
<form action = "person2.cfm"
id = "pers2form"
name = "pers2form"
method = "post"
onsubmit = "return pers1()">
<table>
<td>
<input type = "radio"
class = "moxradio round"
id = "Person"
name = "whereto"
value = "Person">
</td>
<td style = "color: ##946ca6"> Update Person</td>
<tr>
<td>
<input type = "radio"
class = "moxradio round"
id = "Persactiv"
name = "whereto"
value = "PersActiv">
</td>
<td style = "color: ##946ca6; ">Update Activity </td>
</table>
</form>
<input type = "Submit"
name = "subpers2"
id = "subpers2"
class = "submitbut"
style = "display: block; margin:10px auto 10px auto"
value = "Submit">
这工作正常,并正确提交给 person2.cfm其代码如下:
<cfif IsDefined('form.whereto')>
<cfset whereto = form.whereto>
</cfif>
<cfinclude template = person1.cfm>
<cfoutput>
<script>
recheck('#whereto#')
function recheck(target) {
alert('target is ' + target);
document.getElementById(target).checked = true;
}
</script>
</cfoutput>
这应该亲自将支票放回单选框中1。 但事实并非如此。 我在控制台上收到此错误:
TypeError: document.getElementById(...( 为空[了解更多] person2.cfm:393:1
功能重新检查正在拾取正确的目标。 由于 person1.cfm 已经包含在内,因此该目标应该就在那里。 但它似乎找不到它。
person2.cfm的其余部分正确出现。
对第 393 行的引用是虚假的,因为没有第 393 行。 空值必须出现在函数重新检查中。 我到处都做过这种事情,将值放回输入字段并选择框,这一切都在起作用。 但我从来没有用单选按钮做过。也许重新选中一个框有什么不同? 或者也许我做了一些我看不到的愚蠢事情?
谁能发现我做错了什么?
第二个单选按钮的 id 是"Persactiv",但您发送的值是"PersActiv"。区分大小写最终导致getElementById()
找不到 id。