Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过jquery传递的输入类型图像URL值_Php_Jquery_Forms - Fatal编程技术网

Php 通过jquery传递的输入类型图像URL值

Php 通过jquery传递的输入类型图像URL值,php,jquery,forms,Php,Jquery,Forms,我有一个表格,上面有许多输入类型的图像。当用户点击任何图片时,我需要将网页位置替换为图片的url 形式就是, <form action='free.php' id='freeForm' method='post' autocomplete="off"> <? for($j=1;$j<=5;$j++) { ?> <a href="<?=$url;?>" class="anchor-url"> <input type="image" src

我有一个表格,上面有许多输入类型的图像。当用户点击任何图片时,我需要将网页位置替换为图片的url

形式就是,

<form action='free.php' id='freeForm' method='post' autocomplete="off">
<?
for($j=1;$j<=5;$j++)
{
?>
<a href="<?=$url;?>" class="anchor-url"> <input type="image" src="<?=$img;?>" /></a>
 <?
 }
 ?>
 </form>
现在我得到了http://au.yahoo.com'当我单击每个图像时。但我想取代http://au.yahoo.com'与每个图像的URL。如何将PHP变量$url传递到此表单? 有什么想法吗

谢谢

如果我正确理解了你的要求,尽管我还没有尝试过,这应该是可行的。基本上,您可以将click事件绑定到每个图像,并在单击时使用被单击的
input
元素的
src
属性中的值替换窗口位置

$('input[type=image]').click(function(e){
  e.preventDefault();
  window.location.replace($(this).attr('src'));
});
编辑

首先,应向锚元素添加类名:

<form action='free.php' id='freeForm' method='post' autocomplete="off">
<?
for($j=1;$j<=5;$j++)
{
?>
<a href="<?=$url;?>" class="anchor-url"> <input type="image" src="<?=$img;?>" /></a>
 <?
 }
 ?>
</form>

注意我是如何将类添加到锚链接的。这几乎可以被命名为任何东西。这使您能够使用$('.any classname')选择器仅通过jQuery为那些具有该类名的元素进行选择

嗨,谢谢你的回复。我需要用每个输入图像的“a href value”替换窗口位置。我想你的代码会用'image src'值替换位置。啊,对不起。更新我的答案。嘿,谢谢你。我已经更新了我的代码,如上所述。但是$('.anchor url')。单击(函数(e){e.preventDefault();警报($(this.attr('href'));});它不起作用。我看不到任何警报消息。您确定已将
class=“anchor url”
添加到您的锚链接中吗?是的,我确定。因为当我使用var href=$('.anchorurl').attr('href');警惕(href),警报消息始终显示图像的第一个url值。所以我认为点击功能不起作用。
<form action='free.php' id='freeForm' method='post' autocomplete="off">
<?
for($j=1;$j<=5;$j++)
{
?>
<a href="<?=$url;?>" class="anchor-url"> <input type="image" src="<?=$img;?>" /></a>
 <?
 }
 ?>
</form>
$('.anchor-url').click(function(e){
  e.preventDefault();
  window.location.replace($(this).attr('href'));
});