我想知道为什么,在我将以下代码添加到我的页面后,它似乎破坏了我的函数定义的可信度。
<script type="text/javascript">
if (window.addEventListener)
{ // Mozilla, Netscape, Firefox
window.addEventListener('load', WindowLoad, false);
}
else if (window.attachEvent)
{ // IE
window.attachEvent('onload', WindowLoad);
}
function WindowLoad(event) {
var str = "test";
var combo = "<select id=\"users\">";
str = $("div.edit").text();
var ar = str.split("*");
for (i=0; i <= ar.length - 1; i++)
{
if (ar[i] != "")
combo = combo + "<option value=\"" + ar[i] + "\">" + ar[i] +"</option>";
else
combo = combo + "<option value=\"\"></option>";
}
combo = combo + "</select>";
$("div.edit").html(combo);
}
</script>
按钮在
之前有效以下是整个页面:
<font size="14"><b>Admin</b> </font><a href="/worksched/table.php">Return to table</a><button onClick="logout();">Log Out</button>
<br><br><br><br>
Set values for name on left.
<br><br>
<table style="width:100%">
<tr>
<th>Name</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
<th>Sunday</th>
</tr>
<td><div id="edit" class="edit"><? echo $strout ?></div></td>
<td><input id="monday"></td>
<td><input id="tuesday"></td>
<td><input id="wednesday"></td>
<td><input id="thursday"></td>
<td><input id="friday"></td>
<td><input id="saturday"></td>
<td><input id="sunday"></td>
</table><br>
<button onClick="saveval();">Save Values</button>
<button onClick="remuser();">Remove this user</button>
<div id="none"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script type="text/javascript">
if (window.addEventListener)
{ // Mozilla, Netscape, Firefox
window.addEventListener('load', WindowLoad, false);
}
else if (window.attachEvent)
{ // IE
window.attachEvent('onload', WindowLoad);
}
function WindowLoad(event) {
var str = "test";
var combo = "<select id=\"users\">";
str = $("div.edit").text();
var ar = str.split("*");
for (i=0; i <= ar.length - 1; i++)
{
if (ar[i] != "")
combo = combo + "<option value=\"" + ar[i] + "\">" + ar[i] +"</option>";
else
combo = combo + "<option value=\"\"></option>";
}
combo = combo + "</select>";
$("div.edit").html(combo);
}
</script>
<script type="text/javascript">
function logout()
{
var message="logout";
$.post("/worksched/admin.php", {
msg: message
})
.done(function(data){
$('#none').html(data);
});
window.location.href="/worksched/login.php";
//var ar = document.documentElement.innerHTML;
//ar = ar + "fdasssssssssssf";
//document.write(ar);
}
function remuser()
{
var itemID = document.getElementByID("")
var strUser = itemID.options[itemID.selectedIndex].text;
$.post("/worksched/admin.php", {
msg: "delete"
code: struser
})
.done(function(data){
$('#none').html(data);
});
alert("User with name: (" + strUser + ") Has been removed from the database");
}
</script>
在我为页面加载添加了窗口事件监听器之后,我的按钮开始显示为“未捕获的ReferenceError:saveval未定义 在HTMLButtonElement.onclick(admin.php:25)“ 如果我尝试将它全部放在一个块中,则页面加载代码不会执行。
答案 0 :(得分:0)
好吧,我不知道这是否是复制/粘贴错误,但是saveval函数似乎没有在整个页面代码块中的任何位置定义。那可能是罪魁祸首。如果没有,你也可以发布你的saveval函数定义吗?
答案 1 :(得分:0)
也许是因为你在调用之后调用创建函数WindowLoad
,尝试在检查浏览器及其版本的if
之前创建函数。
答案 2 :(得分:0)
我发现了问题。一位朋友指出我在其中一个函数中缺少一个右括号。我现在似乎无法确定它,所以我道歉。