form表单内 checkbox 的 onclick事件 typeError: *** not a function 调用方法类型错误 解决
2012-11-16 13:41
489 查看
form表单内 checkbox 的 onclick事件 typeError: *** not a function 调用方法类型错误 解决
<script type="text/javascript">
function checkboxDan1(obj){
var boxes = document.getElementsByName("checkboxDan1")
for(var i=0;i<boxes.length;i++){
if(boxes[i]!=obj){
boxes[i].checked=false;
}else{
boxes[i].checked = true;
}
}
}
</script>
<form>
<input type="checkbox" name="checkboxDan1" value="1" onclick="checkboxDan1(this);" >
</form>
点击 后 typeError: checkboxDan1 not a function
原因是因为和 input的 name冲突 两个都是 checkboxDan1
所以 解决方法 是 input的name 不能和 js 的函数方法名相同
改成
<script type="text/javascript">
function clickDan1(obj){
var boxes = document.getElementsByName("checkboxDan1")
for(var i=0;i<boxes.length;i++){
if(boxes[i]!=obj){
boxes[i].checked=false;
}else{
boxes[i].checked = true;
}
}
}
</script>
<form>
<input type="checkbox" name="checkboxDan1" value="1" onclick="clickDan1(this);" >
</form>
即可
不能贪图 省力 复制粘贴
<script type="text/javascript">
function checkboxDan1(obj){
var boxes = document.getElementsByName("checkboxDan1")
for(var i=0;i<boxes.length;i++){
if(boxes[i]!=obj){
boxes[i].checked=false;
}else{
boxes[i].checked = true;
}
}
}
</script>
<form>
<input type="checkbox" name="checkboxDan1" value="1" onclick="checkboxDan1(this);" >
</form>
点击 后 typeError: checkboxDan1 not a function
原因是因为和 input的 name冲突 两个都是 checkboxDan1
所以 解决方法 是 input的name 不能和 js 的函数方法名相同
改成
<script type="text/javascript">
function clickDan1(obj){
var boxes = document.getElementsByName("checkboxDan1")
for(var i=0;i<boxes.length;i++){
if(boxes[i]!=obj){
boxes[i].checked=false;
}else{
boxes[i].checked = true;
}
}
}
</script>
<form>
<input type="checkbox" name="checkboxDan1" value="1" onclick="clickDan1(this);" >
</form>
即可
不能贪图 省力 复制粘贴
相关文章推荐
- 在form表单里不要出现submit等关键词,否则调用form.submit();会出现form.submit is not a function的错误;
- 使用vue时Module build failed: TypeError: this._init is not a function错误的解决方法
- 怎样通过onclick事件调用form的id提交方法
- form.submit()不能提交表单的错误原因及解决方法
- js提交表单错误:document.form.submit() is not a function
- JS调用form的方法submit直接提交form的时候,submit事件不响应解决办法
- 表单Form的submit事件不响应的解决方法
- Jquery 清空表单正确姿势(解决错误:$(...).reset is not a function)
- TypeError: 'append' called on an object that does not implement interface FormData 解决方法
- Struts2.5动态方法调用 错误Messages:This method: edit for action product is not allowed!解决方法
- Unity3D Function Not Supported - Unity动画事件提示不支持的解决方法
- Struts Form中Date类型之“argument type mismatch”错误解决方法
- js提交表单错误:document.form.submit() is not a function
- 关于页面报bootstrapValidator is not a function错误的解决方法
- form.submit()不能提交表单的错误原因及解决方法
- jquery中Uncaught TypeError: $(...).ajaxUpload is not a function(…)错误解决方法
- ThinkPHP调用common/common.php函数提示错误function undefined的解决方法
- 解决表单(Form)重置reset is not a function脚本出错
- Messages:This method: edit for action XXX is not allowed!-Struts2.5动态方法调用错误解决方法
- 关于调用listFile()在遍历含有乱码文件时出现input is not valid Modified UTF-8错误的解决方法