jQuery 类型错误:在未实现接口 HTMLInputElement 的对象上调用了“stepUp”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19536963/
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: 'stepUp' called on an object that does not implement interface HTMLInputElement
提问by Stone
I have an error in my use of AJAX:
我在使用 AJAX 时出错:
TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement....plete",[C,p]),--x.active||x.event.trigger("ajaxStop")))}return C},getJSON:functi...
TypeError: 'stepUp' 在没有实现接口 HTMLInputElement....plete",[C,p]),--x.active||x.event.trigger("ajaxStop"))) 的对象上调用C},getJSON:functi...
Here is the parts of my code where I use it:
这是我使用它的代码部分:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
It is my javascript code that works on checkboxes where I defined them before:
这是我的 javascript 代码,适用于我之前定义它们的复选框:
function feedback() {
var boxes = document.getElementsByClassName('box');
for (var j = 0; j < boxes.length; j++) {
if (boxes[j].checked) {
//assign(1);
assign = 1;
} else {
assign = 0;
//assign(0);
}
var wordid = document.getElementsByClassName('wordId')[j];
$.ajax({
url: "assigner.php",
type: "POST",
data: {
wordid: wordid,
assign: assign
}
}).done(function(e) {
/*alert( "word was saved" + e );*/
});
}
}
I tried this but it doesn't work and it doesn't give me any errors.
我试过这个,但它不起作用,它没有给我任何错误。
var newvalue = '';
$('input[name=wordid\[\]]').each(function(index, element) {
newvalue = newvalue + this.value + ',';
});
$.ajax({
url: "assigner.php",
type: "POST",
data: {
wordid: newvalue,
assign: assign
}
}).done(function(e) {
/*alert( "word was saved" + e );*/
});
回答by Rory McCrossan
$.ajax
is not expecting a DOMElement of type HTMLInputElement
in the object you are passing to data
. Try just giving it the value of the field instead:
$.ajax
HTMLInputElement
在您传递给的对象中不期望 DOMElement 类型data
。尝试只给它字段的值:
var wordid = $('.wordId').val();
$.ajax({
url: "assigner.php",
type: "POST",
data: { wordid: wordid, assign: assign}
}).done(function( e ) {
/*alert( "word was saved" + e );*/
});
回答by Girish Sasidharan
You will get all the checkbox values like following.
您将获得如下所示的所有复选框值。
var newvalue='';
$('input[name=wordid\[\]]').each(function(index, element) {
newvalue=newvalue+this.value+',';
});
Then pass the value of variable 'newvalue' to the assign.php file. Hope this may help you.
然后将变量'newvalue' 的值传递给assign.php 文件。希望这可以帮助你。