函数未定义,即使它是(html + JS)

时间:2017-02-20 09:03:24

标签: javascript php html

我制作的标签在点击时打开,CSS使链接看起来像是标签。它曾经在某个时刻起作用,但后来停止了,我不知道某处是否有拼写错误,我错过了什么,或者我是否通过添加最后的函数(Load()以及尝试访问xml而打破它)使用名称将统计信息加载到html文本字段中,但它仍然不完整。)

$(document).ready(function(){
    $('[data-toggle="tooltip"]').tooltip(); 
});
function openRPG(evt, rpgName) {
    // Declare all variables
    var i, tabcontent, tablinks;

    // Get all elements with class="tabcontent" and hide them
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }

    // Get all elements with class="tablinks" and remove the class "active"
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }

    // Show the current tab, and add an "active" class to the link that opened the tab
    document.getElementById(rpgName).style.display = "block";
    evt.currentTarget.className += " active";
}

function load(){
 var xmlhttp = new XMLHttpRequest();
 var idname = document.getElementsByClassName("name");
 xmlhttp.onreadystatechange = function() {
       document.getElementById("").innerHTML = this.t
    if (this.readyState == 4 && this.status == 200) {
		LoadXML(this, idname);
    }
};
xhttp.open("GET", "helper_database.xml", true);
xhttp.send();
}
function LoadXML(xml, name){
var x, i, xmlDoc, nametxt, areEqual;
xmlDoc = xml.responseXML;
nametxt = name;
if (areEqual = xmlDoc.getElementsByTagName("name").toUpperCase() === nametxt.toUpperCase(); //vertailu oikeasti, tähän kohtaan, ks. kommenttirivi 52.
for (i = 0; i< x.length; i++) {
	if (areEqual = xmlDoc.getElementsByTagName("name").toUpperCase() === nametxt.toUpperCase())
	{
		document.getElementById("ComFocus").innerHTML = nametxt;
	}
}
}
}
<html>
<head>
<link rel="stylesheet" href="helper_styles.css">
<style>
table, th, td {
    border: 1px solid black;
}
</style>
<title>Roleplay Helper</title>
</head>
<body>

<h1>A roleplay helper</h1>
<ul class="tab">
<li><a class="tablinks" id="da" href="javascript:void(0)" onclick="openRPG(event, 'DragonAgeRPG')">DragonAgeRPG</a></li>
<li><a class="tablinks" id="dh" href="javascript:void(0)" onclick="openRPG(event, 'DarkHeresy')">DarkHeresy</a></li>
</ul>

<div id="DragonAgeRPG" class="tabcontent">
<p>Dragon age is a dark fantasy roleplaying game, which uses 3d6 system. Main features include ease of use and stunt point system.</p>
<a href="#" data-toggle="tooltip" title="Start by filling out the form, or fill out the name and click 'Load'. Afterwards you can click 'Save' and it is saved onto the database for later use.">Hover over for instructions!<br></a>
Name:<input type="text" class="name" /> <button type="button" text="Save" class="button">Save</button> <button text="Save" class="button" onclick="load()">Load</button>
<table>
	<tr>
		<th>Ability</th>
		<th>Bonus/Penalty<a href="#" data-toggle="tooltip" title="Add the bonus or penalty of your relevant ability.">?</a></th>
		<th>Focuses<a href="#" data-toggle="tooltip" title="List all the focuses you have in a row, separated by space."><p class="helptip">?</p></a></th>
	</tr>
	<tr>
		<td>Communication</td>
		<td><input type="text" class="stat" id="ComBonus"/></td>
		<td><input type="text" class="stat" id="ComFocus"/></td>
	</tr>
	<tr>
		<td>Constitution</td>
		<td><input type="text" class="stat" id="ConBonus"/></td>
		<td><input type="text" class="stat" id="ConFocus"/></td>
	</tr>
	<tr>
		<td>Cunning</td>
		<td><input type="text" class="stat" id="ComBonus"/></td>
		<td><input type="text" class="stat" id="ComFocus"/></td>
	</tr>
	<tr>
		<td>Dexterity</td>
		<td><input type="text" class="stat" id="ComBonus"/></td>
		<td><input type="text" class="stat" id="ComFocus"/></td>
	</tr>
	<tr>
		<td>Magic</td>
		<td><input type="text" class="stat" id="ComBonus"/></td>
		<td><input type="text" class="stat" id="ComFocus"/></td>
	</tr>
	<tr>
		<td>Perception</td>
		<td><input type="text" class="stat" id="ComBonus"/></td>
		<td><input type="text" class="stat" id="ComFocus"/></td>
	</tr>
	<tr>
		<td>Strength</td>
		<td><input type="text" class="stat" id="ComBonus"/></td>
		<td><input type="text" class="stat" id="ComFocus"/></td>
	</tr>
	<tr>
		<td>Willpower</td>
		<td><input type="text" class="stat" id="ComBonus"/></td>
		<td><input type="text" class="stat" id="ComFocus"/></td>

	</tr>
</table>
</div>

<div id="DarkHeresy" class="tabcontent">
<p>Synkkä ja myrskyinen 40k Peli</p>
<input type="text" class="name" />
</div>


<script src="helper_javascript.js"></script>
</body>
</html>

function openRPG(evt, rpgName) {
// Declare all variables
var i, tabcontent, tablinks;

// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
}

// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
}

// Show the current tab, and add an "active" class to the link that opened the tab
document.getElementById(rpgName).style.display = "block";
evt.currentTarget.className += " active";

}

1 个答案:

答案 0 :(得分:0)

你有不完整的&#34;如果&#34; loadXML函数中的语句。 检查此行

if (areEqual = xmlDoc.getElementsByTagName("name").toUpperCase() === nametxt.toUpperCase(); //vertailu oikeasti, tähän kohtaan, ks. kommenttirivi 52.

你错过了#34;)&#34;并且不清楚&#34; if&#34;声明结束。