Javascript 使用图像id传递php会话数据
我想通过单击图像和该图像id将数据传递到另一个页面。 我去拿数据Javascript 使用图像id传递php会话数据,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,我想通过单击图像和该图像id将数据传递到另一个页面。 我去拿数据 <body> <?php include_once("top_temp.php"); ?> <link rel="stylesheet" href="style/mid_style.css"> <div id="pageMiddle"> <div id="06" class="inner"> <img src="style/ankara.png" alt="an
<body>
<?php include_once("top_temp.php"); ?>
<link rel="stylesheet" href="style/mid_style.css">
<div id="pageMiddle">
<div id="06" class="inner">
<img src="style/ankara.png" alt="ankara" width="64" height="64" title="Ankara">
</div>
<div id="34" class="inner">
<img src="style/istanbul.png" alt="ankara" width="64" height="64" title="İstanbul">
</div>
您可以使用GET变量来执行此操作 您的图像链接:
然后,在page.php中,您可以检查ID并执行任何需要执行的操作:
$ID = isset($_GET['id']) ? intval($_GET['id']) : null;
if (empty($ID))
{
// Error handling
}
// Use $ID to fetch whatever data you need
您可以使用JavaScript并从图像创建提交按钮
<form id="form-id" action="target.php">
<img src="file.jpg" onclick="document.getElementById('form-id').submit();" />
<input type="hidden" name="data" value="42" />
</form>
或者你可以使用直接链接
<a href="target.php?data=42><img src="file.jpg" /></a>
您可以在图像周围嵌入表单,并使用javascript执行表单发布。您的图像id将位于隐藏参数处。以下是一个例子:
<form id="Id" name="Form" method="post">
<input type="hidden" name="imgid" value="10">
<a href="#" onclick="document.getElementById('Id').submit();" title="Click to Submit">
<img src="..."/>
</a>
</form>
jQuery中的另一个选项: HTML
<div id="06" class="inner">
<img src="style/ankara.png" alt="ankara" width="64" height="64" title="Ankara">
</div>
你的代码看起来非常错误。首先,为什么在
正文中有一个链接
标签
?您不能在点击时执行表单提交吗?或者它需要一个ajax调用?我只想在单击imgit时将06传递到另一个php页面。其他人看起来也不错,但现在需要快点。谢谢大家
$('.inner img').on('click', function() {
var id = $(this).parent('div').attr('id');
window.location.href = "my-page.php?id="+id;
});