Html外部函数调用

时间:2014-01-10 07:32:52

标签: javascript html html5

我在html中有两个文件,例如example和add-activity。我在示例中有一个函数,我想从add-activity中调用它,甚至我的示例文件也会更新。我已经尽力而为,但没有运气。我怎样才能做到这一点?请帮忙 example.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: &nbsp;&nbsp;&nbsp; <input type="time" name="usrtime" id="usrtime"><br>
To: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="time" name="usrtime1" id="usrtime1"><br><br>
</form>
<button type="button" class="button">Add</button> &nbsp;&nbsp;&nbsp;
<button type="button" class="button" onclick="location.href='example.html'">Cancel</button>
</b>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试在外部文件中添加该java脚本函数,并使用标记将其添加到标头中,并在示例和add-activity文件中调用它