将函数移动到 Java 脚本
moving a function to java script
我需要从以下 html 文档中提取函数,创建一个单独的 js 文档,其中包含该函数并修改我现有的代码,使其包含我的 js 文件。 然后,我必须在我的html文件中创建一个名为"DoTheLink"的新函数。 我将从我的 js 文件中的函数调用该函数。 "DoTheLink"将传递网站变量,并将为按钮设置onclick属性。
这是我必须处理的内容:
<!DOCTYPE html>
<html>
<head>
<title>funky jumper </title>
</head>
<body>
<script>
var surfCaption="You''ve selected: Bird Rock Surf Cam";
var surfButton="Bird Rock Surf Cam";
var surfWeb="http://www.surfline.com/surf-report/birdrock-7-california_4249";
var grandmaCaption="You''ve selected: Grandma''s Weather";
var grandmaButton="Grandma''s Weather";
var grandmaWeb="http://www.weather.com/weather/today/Bronx+NY+10463:4:US";
var dollCaption="You''ve selected: Noodle-head sewing";
var dollButton="Noodle-head sewing";
var dollWeb="http://www.noodle-head.com/2010/01/another-round-of-black-apple-dolls.html";
</script>
<div style="text-align: center">
<table align="center">
<td> <img src="http://nees.oregonstate.edu/killer_wave/wave.jpg" alt="Surf" border="3" height="280" width="172" onclick="uno(surfCaption, surfButton, surfWeb);">
</td>
<td> <img src="http://wirednewyork.com/images/city-guide/liberty/liberty.jpg" alt="Grandma's Weather" border="3" height=280 width=200
onclick="uno(grandmaCaption, grandmaButton, grandmaWeb);">
</td>
<td> <img src="http://4.bp.blogspot.com/__A1V8kztPXs/S1XYcpBScbI/AAAAAAAAA00/S_nd0bNtUR8/s640/helpfulhannahpresent3.jpg" alt="Noodle-head" border="3" height=280 width=180
onclick="uno(dollCaption, dollButton, dollWeb);">
</td>
</table>
<p id="captionUnderTable" >Nothing Selected</p>
<br>
<button id="NewButton" >Click on a picture, then click me to go!</button>
</div>
<script>
function uno(Caption, Button, Web)
{
document.getElementById("captionUnderTable").innerHTML=Caption;
document.getElementById("NewButton").innerHTML=Button;
document.getElementById("NewButton").setAttribute('onclick','window.location.href="'+Web+'";')
<!--When the picture is clicked, go get the variable associated with that picture-->
}
</script>
</body>
</html>
如果您尝试将<脚本>标签之间的内容放在另一个文件中,此链接可能会有所帮助: http://www.htmlgoodies.com/beyond/javascript/article.php/3470901/So-You-Want-An-External-JavaScript-Huh.htm脚本>
相关文章:
- 借助asp.net验证或java脚本对多个文本进行验证
- Java脚本时间添加
- 如何将字符串值从php页面发送到java脚本页面
- java脚本在Chrome和其他浏览器中对LocaleTimeString的不同行为
- Java脚本将URL转换为已保存的URL时出错
- 如何使用Java脚本创建提交按钮's的拖放功能
- 如何在java脚本中验证手机号码
- 使用java脚本更改onClick事件中菜单选项卡的颜色
- 无限的java脚本循环
- 无法在java脚本中调用图像的点击事件函数
- 如何在java中获得浏览器的java脚本控制台输出
- 我的html表单无法验证.请参阅代码片段中的html代码和java脚本
- java脚本的数学方程显示错误的答案
- AngularJS:如何使用java脚本函数更改跨度的ng-show条件
- 如何在java脚本中传递对象数组
- java脚本网站最佳实践
- 无法将java脚本函数与Panel'绑定;s OnLoad事件
- Java脚本访问Location标头's OAuth 2的URL片段
- 从 java 脚本调用函数时 PHP 中出错
- 当没有互联网连接时,谷歌地图Java脚本API处理