点击图片提交表单 [英] submitting form on image click

查看:183
本文介绍了点击图片提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个表单中有多个图像。根据点击的图像,应该使用POST发送特定值。

I have multiple images inside one form. Depending on the image clicked a specific value should be sent with a POST.

这可以在没有javascript的情况下完成吗? (我使用jquery,如果没有的话)。

Can this be done without javascript? (I use jquery, if not).

我试过这样的事情:

I tried something like this:

<input type="image" name="type" value="1" src="images/type1.jpg" />

但是只有图片的坐标被发送,而不是type = 1。

But only the coords of the image were sent, not type=1.

推荐答案

此问题的安全方法是为输入提供唯一的名称并查看哪一个发送了坐标。

The safe approach to this problem is to give the inputs unique names and see which one sends coordinates.

<input type="image" name="submit_blue" value="blue" alt="blue" src="blue.png">
<input type="image" name="submit_red"  value="red"  alt="red " src="red.png">

只有成功的控件才会发送任何数据。因此,测试 submit_blue.x 是否有值,然后测试 submit_red.x 是否有值。

Only the successful control will send any data. So test to see if submit_blue.x has a value, then test if submit_red.x has one.

不需要涉及JavaScript。

There is no need to involve JavaScript at all.

或者,使用常规提交按钮而不是服务器端图像映射。

Alternatively, use regular submit buttons instead of server side image maps.

<button name="action" value="blue"><img src="blue.png" alt="blue"></button>

...请记住,这会在旧IE中破解,因为它不支持<按钮> 正确。

… keeping in mind that this will break in old-IE as it doesn't support <button> properly.

这篇关于点击图片提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆