-1

我有以下 HTML ...

<img id="image1" src="URL" alt="image1" name="image1" width="137" height="119" border="0" style="position: relative; left: -355px; top: 62px;" >

我将如何将以下信息存储到变量中......来自样式属性。

 $variable1 = -355;
 $variable2 = 62;

先感谢您!

更新:

抱歉没有解释清楚,感谢您的帮助。

现在的目标是,在页面上提交表单后,查找所有 img 标签并将 img 标签内的每个属性存储到 PHP 变量中。

然后,我希望将这些值存储到 MySQL 数据库中并在不同的页面上检索它们。

我希望这能解决问题。

4

2 回答 2

0

如果您创建页面,那么您应该能够提前知道这些值,因为您可以先分配变量然后在这些标签中打印它们,或者它们已经预设在模板中的某处,您只需阅读这些价值观。

否则,如果该内容以另一种方式生成,而不是由您的系统生成,那么您将需要一些 JavaScript 代码来“读取”这些属性并在用户提交表单时将其“放在一边”发送给您。通常这是通过添加一些隐藏字段来完成的,其中包含“document.image1.src”之类的内容作为要发送的值。

我不可能在这里给你一段代码,因为我们不知道你的应用程序的结构是什么样的。但是,这应该让您了解它是如何工作的。

于 2012-12-18T23:46:07.880 回答
0

你可以这样做:

When your jQuery plugin sets image attributes you could also add hidden input fields to the form with those attributes values. This is possible if the plugin api has events available. Otherwise you would need to extend it by your own. After subbmiting form, server would receive hidden input fields values along with other. So in PHP this would be accesible from the $_GET or $_POST global array (depending on form method).

Another way:

You could also capture the moment when user clicks submit button on the form. Then - stop default behavior. Next send an Ajax call to the server, passing current image attributes values. Server can store those values in the database, or do whatever you want and return a response. After response you can trigger the form submission programmatically.

于 2012-12-19T00:10:57.710 回答