javascript 未捕获的错误:语法错误,无法识别的表达式:#[object HTMLDivElement]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29716171/
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
Uncaught Error: Syntax error, unrecognized expression: #[object HTMLDivElement]
提问by nestedloop
I'm passing a value to codeigniter function for getting a result. But the ajax value does not pass to the php function.
我正在将一个值传递给 codeigniter 函数以获得结果。但是ajax 值不会传递给php 函数。
My script function follows :
我的脚本功能如下:
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<Script>
$(document).ready(function() {
$("#up").on('click',function(){
if ($("#incdec").val() < $(this).data("max")) {
$("#incdec").val(parseInt($("#incdec").val())+1);
}
});
$("#down").on('click',function(){
if ($("#incdec").val() > $(this).data("min")) {
$("#incdec").val(parseInt($("#incdec").val())-1);
}
});
});
$(document).ready(function() {
$(".butt").on('click',function(){
var e=$(".aa").val();
alert(e);
$.ajax({
type:"POST",
data:"id="+e,
url:"<?php echo site_url('pages/getit');?>",
success: function(html){
$('#'+dataprocess).html(html);
}
});
});
});
</script>
My HTML code :
我的 HTML 代码:
<input type="text" name="incdec" id="incdec" value="0" class="aa"/>
<input type="button" class="butt" id="up" value="Up" data-max="5" />
<input type="button" id="down" value="Down" data-min="0" class="butt"/>
<div id="dataprocess"></div>
But I'm getting an error as follows:
但我收到如下错误:
Uncaught Error: Syntax error, unrecognized expression: #[object HTMLDivElement]
Uncaught Error: Syntax error, unrecognized expression: #[object HTMLDivElement]
Please help me find my mistake.
请帮我找出我的错误。
回答by nestedloop
In this bit of code:
在这段代码中:
success: function(html){
$('#'+dataprocess).html(html);
}
you are appending a string, namely '#', to an object, dataprocess.
您将一个字符串,即'#'附加到一个对象dataprocess。
The object is converted to a string, '[object HTMLDivElement]', which tells its type.
该对象被转换为一个字符串,'[object HTMLDivElement]',它告诉它的类型。
Try this instead:
试试这个:
success: function(html){
$('#dataprocess').html(html);
}
EDIT:
编辑:
The way jquery selectors work, in this case the 'by-id' selector, you have the 'id' marker, '#', immediatelyfollowed by the id of the control you are trying to select, in this case 'dataprocess'.
该方法jQuery选择工作,在这种情况下,“通过ID”选择,你有“身”的标记,“#”,立即其次是您要选择控件的ID,在这种情况下,“dataprocess”。
Here is a useful resource about jquery selectors:
这是一个关于 jquery 选择器的有用资源:
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
Hope this helps. Cheers!
希望这可以帮助。干杯!
回答by Uraj
Please try this ajax as blw:
请试试这个 ajax 作为 blw:
$('#dataprocess').html(html);