[英]JQuery JS Uncaught Error: Syntax error, unrecognized expression:
So, I have this issue that has been bugging me and I just can't seem to fix it. 所以,我有这个问题一直困扰着我,我似乎无法修复它。 The error that comes up is this: 出现的错误是这样的:
Uncaught Error: Syntax error, unrecognized expression: [{"type":"header","subtype":"h1","label":"Another test form"},{"type":"checkbox-group","label":"Checkbox Group","name":"checkbox-group-1497353080484","values":[{"label":"Option 1","value":"option-1","selected":true}]},{"type":"header","subtype":"h1","label":"Header"},{"type":"number","label":"Number","className":"form-control","name":"number-1497353081884"},{"type":"text","label":"Text Field","className":"form-control","name":"text-1497353083345","subtype":"text"}] 未捕获错误:语法错误,无法识别的表达式:[{“type”:“header”,“subtype”:“h1”,“label”:“另一个测试表单”},{“type”:“checkbox-group”,“ label“:”Checkbox Group“,”name“:”checkbox-group-1497353080484“,”values“:[{”label“:”Option 1“,”value“:”option-1“,”selected“:true }]},{ “类型”: “标题”, “子类型”: “H1”, “标签”: “头”},{ “类型”: “号码”, “标签”: “号码”, “类名” :“form-control”,“name”:“number-1497353081884”},{“type”:“text”,“label”:“Text Field”,“className”:“form-control”,“name”: “文本1497353083345”, “子类型”: “文本”}]
I have managed to track down the line of code that is causing this issue, which is this: 我设法找到导致此问题的代码行,这是:
forms = $(document.getElementById('formData').getAttribute("value")),
Now, I have no idea why this is causing this issue. 现在,我不知道为什么会导致这个问题。 The content coming in is correct. 进来的内容是正确的。 This is all being done within a JQuery function, in fact the whole JQuery function looks like this: 这都是在JQuery函数中完成的,实际上整个JQuery函数看起来像这样:
jQuery(function($) { var $fbEditor = $(document.getElementById('fb-editor')), $formContainer = $(document.getElementById('fb-rendered-form')), forms = $(document.getElementById('formData').getAttribute("value")), fbOptions = { formData: forms, dataType: 'json', onSave: function(){ $fbEditor.toggle(); $formContainer.toggle(); $('form', $formContainer).formRender({ formData: formBuilder.formData }); } }, formBuilder = $fbEditor.formBuilder(fbOptions); $('.edit-form', $formContainer).click(function() { $fbEditor.toggle(); $formContainer.toggle(); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
So, I am not that experienced with JavaScript, JQuery or any of the rest of this. 所以,我不熟悉JavaScript,JQuery或其他任何一个。 So it could very well be a simple issue but I cannot currently figure out what it is. 所以它很可能是一个简单的问题,但我现在无法弄清楚它是什么。 Can somebody else tell me where I have gone wrong and possibly how to fix it? 别人可以告诉我哪里出错了,可能还有怎么解决?
forms = $(document.getElementById('formData').getAttribute("value")),
Try removing the $() in the code above. 尝试删除上面代码中的$()。 As per poohitan, its a selector but it doesn't appear to be doing anything at all. 根据poohitan,它是一个选择器,但似乎根本没有做任何事情。
From the error I guess document.getElementById('formData').getAttribute("value")
is a JSON string. 从错误我猜document.getElementById('formData').getAttribute("value")
是一个JSON字符串。
You have wrapped it into jQuery object constructor $(...)
, and it fails because jQuery expectes the parameter to be a selector (like .classname
), DOM element, or another jQuery element. 您已将其包装到jQuery对象构造函数$(...)
,并且它失败,因为jQuery将参数指定为选择器(如.classname
),DOM元素或其他jQuery元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.