[英]unable to call javascript function using button's onclick event
My display.php
file has the code for fetching data from database and display it in html table. 我的display.php
文件具有用于从数据库中获取数据并将其显示在html表中的代码。 I want to display this table on my index page only in the <div> displayTable
section and for that I've called the showTbale()
using onclick of my button abc
. 我只想在<div> displayTable
部分中的索引页面上显示此表,为此,我使用按钮abc
onclick调用了showTbale()
。 But the problem is that the function showTable()
doesn't get called even though I've successfully called the logoutEmp()
using the onclick of the logoutButton
. 但是问题是,即使我已经使用logoutButton
的onclick成功调用了logoutEmp()
也无法调用showTable()
函数。 I don't understand what's the problem. 我不明白这是什么问题。 Any help would be appreciated. 任何帮助,将不胜感激。
NOTE: I tried using form action to call display.php
but it displays the table in another white page which I don't want. 注意:我尝试使用表单操作来调用display.php
但它在另一个不需要的白页中显示该表。 Also I don't want to include display.php
code in my index page. 我也不想在索引页面中包含display.php
代码。
say this is my index file : 说这是我的索引文件:
<head>
<meta http-eqiv="X-UA-Compatible" content="IE=9,chrome=1">
<link rel="stylesheet" type="text/css" href="page_style.css">
<script src="jquery-1.10.1.js"></script>
</head>
<body>
<script>
function logoutEmp()
{
window.location="saveLogout.php";
}
function showTable()
{
var month= $('#mnth: selected').val();
alert (month);
$("#displayTable").load("display.php",{ mnth: month});
}
</script>
<h1>Employee Account</h1>
<div id="logoutEmp">
<button type="button" id="logoutButton" onclick="logoutEmp()">Logout</button>
</div>
<hr>
<div id="shw">
<select name="mnth">
<option value="Jan">January</option>
<option value="Feb">February</option>
<option value="Mar">March</option>
<option value="Apr">April</option>
<option value="May">May</option>
<option value="Jun">June</option>
<option value="Jul">July</option>
<option value="Aug">August</option>
<option value="Sep">September</option>
<option value="Oct">October</option>
<option value="Nov">November</option>
<option value="Dec">December</option>
</select>
<button type="button" id="abc" onclick="showTable()">Display</button>
<div id="displayTable">
</div>
</div>
</body>
</html>
change your code like this: 像这样更改代码:
function logoutEmp(){
window.location.href="saveLogout.php";
}
You had an extra slash, and a syntax error. 您有一个额外的斜杠和语法错误。
Also, you should change showTable
that was wrong as well : 此外,您还应该更改错误的showTable
:
function showTable()
{
var month= $('#mnth').val();
alert (month);
$("#displayTable").load("display.php",{ mnth: month});
}
And add your id to your select: 并将您的ID添加到您的选择中:
<select name="mnth" id="mnth">
I guess: 我猜:
function logoutEmp()
{
window.location="saveLogout.php";
\}
that backslash should not be there: 反斜杠不应该存在:
function logoutEmp()
{
window.location="saveLogout.php";
}
you can not call showTable()
because in JavaScript if there is any error script after that error would not work. 您无法调用showTable()
因为在JavaScript中,如果该错误之后没有任何错误脚本,该错误将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.