input type="image"

  php中如何取得image按钮传递的name值? 收藏
使用连接的传递方式会在浏览栏里面出现变量值,这样看上去不舒服,如果使用hidden来提交呢,又觉得没有必要,因为既然image有name属性,就应该能取到的。
  我需要使用图片按钮来美化我的web,但是使用连接的传递方式会在浏览栏里面出现变量值,这样看上去不舒服,如果使用hidden来提交呢,又觉得没有必要,因为既然image有name属性,就应该能取到的,何必要多加一个变量呢?在bbs里贴了好几天也没人回答,我就只能自己看书想办法,后来找到了!

  在表单中的image作为submit的话,会产生两个相关变量,譬如:
<input type=image src="..." name=aaa>
然后呢,在提交的过程中会产生两个变量,为aaa_x和aaa_y
其中包含了图片在屏幕上的具体位置x和y
然后么在php中只要对aaa_x和aaa_y判断一下就行了

  不需要任何隐藏域,javascript,和连接传值行为

 

 

type=image
This is used for graphical submit buttons rendered by an image rather than a text string. The URL for the image is specified with the src attribute. The image alignment can be specified with the align attribute. In this respect, graphical submit buttons are treated identically to IMG elements, so you can set align to left, right, top, middle or bottom. The x and y values of the location clicked are passed to the server: In the submitted data, image fields are included as two name/value pairs. The names are derived by taking the name of the field and appending ".x" for the x value, and ".y" for the y value.
<p>Now choose a point on the map:

    <input type=image name=point src="map.gif">
Note: image fields typically cause problems for text-only and speech-based user agents!


http://www.w3.org/TR/REC-html32.html

 

 

 

INPUT type=image元素|input type=image对象

--------------------------------------------------------------------------------

创建一个图像控件,该控件单击后将导致表单立即被提交。

注释

x 坐标将以控件名称后加 .x 提交,y 坐标将以空间名称后加 .y 提交。任何 value 属性都将被忽略。src 属性指定了 IMG元素。

在 Internet Explorer 5 中支持下列图像和视频文件格式。

.avi - 交错音频视频 (AVI)
.bmp - Windows 位图 (BMP)
.emf - Windows 增强图元文件 (EMF)
.gif - 图像交换格式 (GIF)
.jpg, .jpeg - 移动图像专家组 (JPEG)
.mov - Apple QuickTime 电影 (MOV)
.mpg, .mpeg - 移动图像专家组 (MPEG)
.png - 便携网络图像 (PNG)
.wmf - Windows 图元文件 (WMF)
.xbm - X 位图 (XBM)

 

 

HTML标记
<input TYPE="image" NAME="thisname" SRC="path/image">

PHP对此标记支持的自动生成两个变量
$_POST[thisname_x] --鼠标点击图片的X位置
$_POST[thisname_y] --鼠标点击图片的Y位置


演示:
======

index.html
----------
<html>
<head>
<title>测试信息</title>
</head>
<body>
<form action="post.php" method="post" name="form1">
<input type="hidden" name="image" value=http://wzsky.net/html/article/php/php2/"bg.jpg">
<input type=image src=http://wzsky.net/html/article/php/php2/"bg.jpg" name="sub">
</form>
</body>
</html>

--------------------------------------------------------------------------------

post.php
<html>
<head>
<title>操作...</title>
</head>
<body>
<pre>
<?php
$c=getimagesize("$_POST[image]");    //获得图片尺寸

if($_POST[sub_x]<$c[0]/2){        //鼠标点击图片X位置为图片左半部

    if($_POST[sub_y]<$c[1]/2){    //鼠标点击图片的Y位置为上半部
        echo "你点击了图片的左上半部分 x={$_POST[sub_x]} y={$_POST[sub_y]}";
    }else{
        echo "你点击了图片的左下半部分 x={$_POST[sub_x]} y={$_POST[sub_y]}";
    }
}else{
    if($_POST[sub_y]<$c[1]/2){    //鼠标点击图片的Y位置为下半部
        echo "你点击了图片的右上半部分 x={$_POST[sub_x]} y={$_POST[sub_y]}";
    }else{
        echo "你点击了图片的右下半部分 x={$_POST[sub_x]} y={$_POST[sub_y]}";
    }
}
?>
</pre>
<!--
图片走向
       
          0 |
          --+----------------------------------------------------→x++(图片的宽度)
            |
            |
            |
            |
            |
            |
            |
            |
           ↓(Y++图片的高度)
-->
</body>
</html>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值