javascript 类型错误:对象不是函数,当它是!
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6822635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: object is not a function, when it is!
提问by AVProgrammer
I am having trouble with some Ajax functionality.
我在使用某些 Ajax 功能时遇到了问题。
I have a single dropdown that needs to update a record when the option changes. Here is a snippet of the Javascript:
我有一个下拉菜单,需要在选项更改时更新记录。这是 Javascript 的一个片段:
function changeResponsibleParty(selectObj, targetDiv){
var idx = selectObj.selectedIndex;
var which = selectObj.options[idx].value;
target = document.getElementById(targetDiv);
target.value = which;
document.forms["changeResponsibleParty"].submit();
}
And the HTML:
和 HTML:
<form name="changeResponsibleParty" action="javascript:changeResponsiblePartyAjax('project_todos');" method="post" style="display:inline;">
<input type="hidden" name="todo_id" id="todo_id_15" value="15" />
<input type="hidden" name="project_id" id="project_id_15" value="2" />
<input type="hidden" name="user_id" id="user_id_15" value="" />
<select name="user_id_pick" id="user_id_pick_15" onchange="changeResponsibleParty(this, 'user_id_15');" style="border:0;">
<option value="0">Anyone</option>
<option value="1" selected="selected">Allen McCabe</option>
<option value="2">Thomas Martinez</option>
</select>
</form>
I am using the function to update a hidden input element because for some reason, the tag was posting 1 regardless of which option I chose (1 is my user_id, which I set as selected if the database record value is 1.
我正在使用该函数来更新隐藏的输入元素,因为出于某种原因,无论我选择哪个选项,标签都会发布 1(1 是我的 user_id,如果数据库记录值为 1,我将其设置为已选择。
Can anyone see what is wrong here?
任何人都可以看到这里有什么问题吗?
回答by Dr.Molle
You use changeResponsiblePartyas name for the form and also as name for the function, which will cause conflicts. Rename one of them.
您使用changeResponsibleParty作为表单名称和函数名称,这会导致冲突。重命名其中之一。