使用javascript单击图像后的页面链接
Page link after clicking image using javascript
所以我试图简单地根据网页上按下的图像重新定位页面。我以前有代码,但是对于我必须做的 100 件事来修复东西,它不再起作用了。谁能弄清楚为什么?
因此,当您单击现在页面上的图像cloudybubble.png
时,它将带您进入 cloudy_name.php
.并且还会有其他图像将您带到其他页面来执行此操作。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WhethertheWeather</title>
<!--<link rel="stylesheet" type="text/css" href="demo/css/screen.css" media="all" />-->
<script src="http://www.adrianpelletier.com/mint/?js" type="text/javascript"></script>
<script type="text/javascript" src="demo/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="demo/scripts/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="demo/scripts/execute.js"></script>
<script>
function showWeather(_Weather) {
//alert(Weather);
myform._Weather.value=Weather;
// alert(Weather);
// ._Weather
myform.submit();
}
$(document).ready(function() {
$('cloudybubble.png').click(function() {
window.location="http://http://www.tcnjart.com/christineaustin/whethertheweather/cloudy_name.php;"
});
});
// window.location="http://http://www.tcnjart.com/christineaustin/whethertheweather/cloudy_name.php"; //
</script>
</script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/gradientsky.jpg">
<div id="weather">
<ul id="nav-reflection">
<form method="post" action="cloudy_name.php" id="myform">
<li class="button-color-1"><a href="javascript:showWeather('cloudy')"; title="My fancy link"><img src="images/cloudybubble.png" width="211" height="180" align="left"></a></li>
<input type="hidden" name="weather" value="whatever">
</form>
</ul>
</div>
</body>
</html>
新脚本
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WhethertheWeather</title>
<!--<link rel="stylesheet" type="text/css" href="demo/css/screen.css" media="all" />-->
<script src="http://www.adrianpelletier.com/mint/?js" type="text/javascript"></script>
<script type="text/javascript" src="demo/scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="demo/scripts/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="demo/scripts/execute.js"></script>
<script>
function showWeather(_Weather) {
//alert(Weather);
myform._Weather.value=Weather;
// alert(Weather);
// ._Weather
myform.submit();
}
$('#cloudybubble').click(function() {
window.location = "http://http://www.tcnjart.com/christineaustin/whethertheweather/cloudy_name.php;"
});
</script>
</script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/gradientsky.jpg">
<div id="weather">
<ul id="nav-reflection">
<form method="post" action="cloudy_name.php" id="myform">
<li class="button-color-1"><a href="javascript:showWeather('cloudy')"; title="My fancy link"><img id="cloudybubble" src="images/cloudybubble.png" width="211" height="180" align="left" />
</a></li>
<input type="hidden" name="weather" value="whatever">
</form>
</ul>
</div>
</body>
</html>
编辑:修改以考虑评论中的新信息。
我们可以为您的页面中的所有图像通用地工作,以便它们使用相同的JavaScript。
在 HTML 中,将超链接放回 a 标记中。然后,在 a 标签中添加一个类,我建议"weatherLink"。然后将您要登录的文本放入数据库中,即"多云",并将其作为链接的 id。
.HTML:
<li class="button-color-1">
<a id="cloudy" class="weatherLink" href="http://www.tcnjart.com/christineaustin/whethertheweather/cloudy_name.php" title="My fancy link">
<img src="images/cloudybubble.png" width="211" height="180" align="left" />
</a>
</li>
现在我们的 JavaScript 需要更新 jQuery 点击处理程序,如下所示。
JavaScript:
$(document).ready(function () {
$('a.weatherLink').click(function (e) {
e.preventDefault();
showWeather(this.id);
window.location.href = this.href;
return false;
});
});
现在,如果您添加任何其他图像,只需将超链接保留在 a 标签中,为其提供 weatherLink 类,并为其提供一个可以传递给 showWeather() 的唯一 ID。给定正确的 HTML,您不需要再复制任何 JavaScript。
这是一个jsFiddle测试页面,供您查看结果:http://jsfiddle.net/willslab/jkB9z/9/
你绝对应该在服务器端这样做。
如果你的用户没有javascript怎么办?相信我,其中有很多(主要是出于安全原因)。
将表单的操作定义为某个 PHP 页面,处理您需要执行的更改或 w/e,并相应地重定向用户(使用 header('Location: http://www.hi.com');
)。
将id
添加到img
标签中,并在选择器中使用它。
- 当链接javascript承诺时,如何处理then()函数中的条件
- 如何在grails中链接javascript引导程序方法
- 在PHP代码中单击链接javascript函数调用
- 随机链接javascript以忽略当前页面
- 如何链接javascript承诺和错误
- 在从ruby on rails中的资产管道加载的布局上链接Javascript函数
- 用链接 JavaScript 替换 HTML 的问题
- 突出显示当前链接 Javascript
- 如何在数组中添加超链接(Javascript)
- 有没有一种简单的方法可以在节点上双击 vis.js 创建超链接/javascript-action
- Facebook分享深度链接 - Javascript
- 链接 JavaScript 变量
- 在 AJAX 成功的新选项卡中打开链接 - Javascript
- window.打开一个新页面,然后单击新页面中的链接 - JavaScript
- 链接 JavaScript 函数
- 在 PHP 中链接 Javascript 文件
- 在拖动事件期间禁用链接 Javascript
- 文本框使用 if else 语句打开我的链接 JavaScript
- ajax脚本运行后指向页面的链接(javascript锚点?)
- 动态创建链接Javascript