0

when we submit a form using this type of input, the coordinates (x,y) are appended to the result.

it works if I dynamically create 2 hidden inputs, but I wanted something different.
Event or MouseEvent would be great, but I couldn't make it work

here's my current code: (it works fine)

var input = document.createElement("input");
input.type = "hidden";
input.name = "x";
input.value = posx;
my_form.appendChild(input);

input = input.cloneNode(false);
input.name = "y";
input.value = posy;
my_form.appendChild(input);

I'll give you an example of situation

Let's imagine that near to the image form element there is a plain text that says: Click in the image below in any position greater than 20 and lesser than 60

A normal person would read this and click normally.
But I need to, as a robot without hands, simulate the same click event

4

2 回答 2

2

在没有完全理解你在这里尝试做什么的情况下(你的问题有点模糊,IMO),我不得不问这个:你有没有考虑过使用 jQuery 或其他 javascript 库/框架?我理解有时,对于非常简单的网站,它是矫枉过正的。但是,减轻自己解决这些问题的麻烦可能是值得的。

据我所知,您正在使用“图像”表单元素提交表单,并且您想模拟单击图像元素以检索某物的 x/y 坐标。我可能是错的。你能在你的细节上更明确吗?

当我更多地了解您的问题时,我会看看是否可以向您展示如何在 jQuery 中执行此操作。

于 2009-11-05T19:24:55.517 回答
1

我不知道你试图将结果附加到什么。表格中的值?这是自动的,不需要代码(它们遇到 x 和 y,或 elementname.x 和 elementname.y)。

评论后编辑:
可以通过当时不制作元素来避免节点插入事件;即在表单中添加 x 和 y。然后在事件中,您可以简单地设置它们的值。当然你也可以绑定不同的事件,我不知道你的情况,但我做了一个例子它使用附加到页面本身的主体的 onClick 事件。相反,您可能希望将特定的 onClick 事件绑定到不同的可点击项目并为它们插入您自己的位置,但在我的情况下,我在页面上提交了鼠标的位置。如果这没有帮助,请评论原因,我会看看我是否可以再次修改它。

于 2009-11-05T19:32:51.547 回答