我在html中有两个文件,即example和add-activity。我在示例中有一个函数,我想从add-activity中调用它,以便更新我的示例文件。我已经尽了一切努力,但没有运气。我怎样才能做到这一点?请帮助 example.html的Html外部函数调用
<html>
<head>
<title>example</title>
<script type="text/javascript">
function displayResult()
{
var table=document.getElementById("myTable");
var row=table.insertRow(0);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
var cell3=row.insertCell(2);
var cell4=row.insertCell(3);
cell1.innerHTML=document.getElementById('txtact').value;
cell2.innerHTML=document.getElementById('txtcat').value;
cell3.innerHTML=document.getElementById('datetime').value;
cell4.innerHTML=document.getElementById('datetime1').value;
}
</script>
</head>
<body>
<form>
Username: <input type="text" name="txtname"><br>
Branch: <input type="text" name="txtbranch"><br>
<table style="border:1px solid black;" cellpadding="-2">
<tr>
<th width="70%" bgcolor="#D8E4BC">Activity</th>
<th><button type="button" onclick="location.href='add-activity.html'">Add</button>
</th>
</tr>
</table>
<table id="myTable" border="1" width="33.69%">
<tr>
<td>Coll Activity</td>
<td>category</td>
<td>From</td>
<td>To</td>
</tr>
</table>
<br><br><br><br><br><br>
<button type="submit" onclick="location.href='submit.html'">Submit</button>
</form>
</body>
</html>
附加activity.html
<html>
<head>
<title>Add activity</title>
<style type="text/css">
button {
width: 10em;
padding: -2em;
color: #ffffff;
text-shadow: 1px 1px 1px #000;
-webkit-box-shadow: 2px 2px 3px #999;
box-shadow: 2px 2px 2px #bbb;
background-color: #7F98E5;
background-image: -webkit-gradient(linear, left top, left bottom, from(#e9ede8), to(#7F98E5),color-stop(0.6, #1947D1));
}
</style>
</head>
<body>
<b><font face="verdana" size="4">
<table style="border:1px solid black;">
<tr>
<td width="43%" bgcolor="#D8E4BC">Add Activity</td>
</tr>
</table>
</font>
<br>
<br>
<form>
Activity: <input type="text" placeholder="Enter Activity..." size="33" id="txtact" name="txtact"><br>
Category: <input type="text" placeholder="Enter Category..." size="33" id="txtcat" name="txtcat"><br>
Duration:<br><br>
From: <input type="time" name="usrtime" id="usrtime"><br>
To: <input type="time" name="usrtime1" id="usrtime1"><br><br>
</form>
<button type="button" class="button">Add</button>
<button type="button" class="button" onclick="location.href='example.html'">Cancel</button>
</b>
</body>
</html>
你可以请发表该功能,以及你如何打电话给他们? –
你在使用iframe吗?如果没有,最好的办法是删除js代码并将其放在一个单独的“.js”文件中,并将该文件包含在每个页面中。 –
我在我的示例文件中有一个表格,我想通过添加活动文件中的用户输入来更新该表格。我的添加活动文件有一些字段,并添加按钮,当我输入字段值,并单击添加按钮,它应该更新我的表中的示例文件的那些值 – user3180748