我终于制作了我的脚本,获取图像的链接并在主要照片中显示。 这是链接 http://www.fisicasanitaria.it/form/form.php 当表单在另一页面中提交页面重定向时 http://www.fisicasanitaria.it/form/welcome.php
这是此页面的代码
<link rel="stylesheet" href="form.css">
<script type="text/javascript" src="js/jquery-3.1.0.min.js"></script>
<script src="js/script.js"></script>
<?php
/* welcome.php */
//$_SESSION variables become available on this page
session_start();
?>
<div class="body content">
<div class="welcome">
<div class="intro">
<div class="alert alert-success"><?= $_SESSION['message'] ?></div>
<img class="dim" src="<?= $_SESSION['avatar'] ?>" ><br />
Welcome <span class="user"><?= $_SESSION['username'] ?></span>
Welcome <span class="email"><?= $_SESSION['email'] ?></span>
Welcome <span class="password"><?= $_SESSION['password'] ?></span>
</div>
<section id="content"></section>
<?php
$mysqli = new mysqli("myHost", "myUser", "myRoot", "database");
$sql = "SELECT username, avatar,email,password, id FROM users";
//$result = mysqli_result object
$result = $mysqli->query( $sql );
?>
<div id='registered'>
<span>All registered users:</span>
<?php
//returns associative array of fetched row
while( $row = $result->fetch_assoc() ){
echo "<div class='userlist'><span>".$row['username']."</span><span>".$row['email']."</span><br />";
echo "<a class='prova' >{$row['user']}<img class='foto' id=\"{$row['id']}\" src='".$row['avatar']." '></a></div>";
// echo "<a href=\"welcome.php?id={$row['id']}\">{$row['user']}</a>";
}
?>
</div>
</div>
</div>
使用此脚本我得到底部图像的链接,我想显示并替换主要的照片。
jQuery(function () {
jQuery(" #registered img").hover(function(e) {
var currentId = jQuery(this).attr("src");
var ind = currentId;
jQuery("body > div > div > div.intro > img").fadeOut();
jQuery("body > div > div > div.intro > img").attr("src",ind).fadeIn();
e.preventDefault();
});
});
为什么foto会出现两次这种奇怪的效果? 我不太了解命令preventDefault,这是正确的吗? 谢谢