我想使用JSFiddle来更轻松地通过stackoverflow提供帮助。
我尝试添加以下代码:
<form method='post' action='' onsubmit="return onFormSubmitted()">
<input type='text' name='Leerling' id='Leerling'>
<input type='text' name='Opmerking' id='Opmerking'>
<input type='submit' name='submit' value='Send'>
</form>
使用此JavaScript代码:
function onFormSubmitted()
{
event.preventDefault();
var ref = new Firebase("https://mydatabase.firebaseio.com/");
var _leerling = document.getElementById("Leerling").value;
var _opmerking = document.getElementById("Opmerking").value;
var postsRef = ref.child("opmerkingen");
var newPostRef = postsRef.push({
leerling: _leerling,
opmerking: _opmerking
});
var postID = newPostRef.key();
var leerlingRef = ref.child("leerling").child(_leerling);
leerlingRef.once('value', function(snapshot) {
if( snapshot.val() === null ) {
/* does not exist */
var leerlingNummer = _leerling.substring(0,6).trim();
ref.child("leerling").child(leerlingNummer).set({
"naam": _leerling.substring(7,33).trim(),
"klas": _leerling.substring(34,38)
})
ref.child("leerling").child(leerlingNummer).child("opmerkingen").push({
"opmID": postID
})
} else {
var leerlingPostRef = snapshot.ref().child("opmerkingen");
leerlingPostRef.push({"opmID": postID});
}
});
}
我添加了这个外部库:https://cdn.firebase.com/js/client/2.2.1/firebase.js
首先:关闭标签在编辑器中标记为红色。 此外,在运行它时,输入2个字段的值,点击发送,我得到以下消息:
{&#34;错误&#34;:&#34;外壳形式无法验证{&#39; html_initial_name&#39;:u&#39; initial-js_lib&#39;,&#39;表格&#39 ;:,&#39; html_name&#39;:&#39; js_lib&#39;,&#39; html_initial_id&#39;:u&#39; initial-id_js_lib&#39;,&#39;标签&#39;:你&#39; Js lib&#39;,&#39; field&#39;:&#39; help_text&#39;:&#39;&#39;,&#39; name&#39;:&#39; ; js_lib&#39;} {&#39; html_initial_name&#39;:u&#39; initial-js_wrap&#39;,&#39; form&#39;:,&#39; html_name&#39;:&#39; js_wrap&#39;,&#39; html_initial_id&#39;:u&#39; initial-id_js_wrap&#39;,&#39;标签&#39;:u&#39; Js wrap&#39;,&#39; field&# 39;:,&#39; help_text&#39;:&#39;&#39;,&#39; name&#39;:&#39; js_wrap&#39;}&#34;}
虽然这段代码实际运行良好。关于如何使用JSFiddle,我缺少什么?
答案 0 :(得分:0)
对于结束标记,JSFiddle查找格式正确的HTML文档,在您的情况下不是,因为标记未关闭,这就是标记有错误的结束标记的原因,尝试关闭输入标记,然后应该解决:
<input type='text' name='Leerling' id='Leerling' />