简体   繁体   English

用户输入后更改div服务器端的类

[英]change class of div server-side after user input

I'm working on a project where users can choose squares of a big field and "book" them. 我正在做一个项目,用户可以选择大视野的正方形并“预订”它们。 The grid is just a html table with each having a unique id (1,2,3...). 网格只是一个html表,每个表都有唯一的ID(1,2,3 ...)。 similar to this example: http://jsfiddle.net/MvFx9/ $ Now after they submit a simple form, the chosen squares turn yellow. 类似于以下示例: http : //jsfiddle.net/MvFx9/ $现在,他们提交了简单的表单后,所选的正方形变为黄色。 i do this with javascript, search all elements by its id and change their class. 我使用javascript执行此操作,通过其ID搜索所有元素并更改其类。 And it works perfect. 而且效果很好。

What i want to do now is to change the class of each chosen element server-side. 我现在要做的是更改服务器端每个选定元素的类。 So that when a new user loads the page, he sees yellow squares, which are already booked by other users. 这样,当新用户加载页面时,他会看到黄色的正方形,该正方形已经被其他用户预订。

But i dont know how to do it, i guess its not possible with javascript, so i tried it with php. 但是我不知道该怎么做,我想用javascript是不可能的,所以我尝试用php。 Is there a equivalent getelementbyid function and how can i change the class of each element? 是否有一个等效的getelementbyid函数,如何更改每个元素的类?

Please give me an advice, thanks. 请给我一个建议,谢谢。

In some way, you will need to save which squares have been booked by others 以某种方式,您将需要保存其他人预订的正方形

The general idea : 总体思路:

1) Whenever a user click on a square, you save the id in a table in the database. 1)每当用户单击一个正方形时,您就将ID保存在数据库的表中。 You can use a form (it will reload the page) or if you want it cleaner, you perform an AJAX call. 您可以使用表单(它将重新加载页面),或者如果您希望它更整洁,则可以执行AJAX调用。

2) When displaying the page, you retrieve the id that have been saved and set the class "already_booked" for them dynamically. 2)显示页面时,检索已保存的ID,并为它们动态设置类“ already_booked”。

您需要的是一个数据库来知道预订哪些景点,其他任何事情都将花费您很长的时间并且效率不高。

DOMDocument::getElementById('element_id')

Use the PHP DOMDocument class to do this. 使用PHP DOMDocument类来执行此操作。

http://php.net/manual/en/domdocument.getelementbyid.php http://php.net/manual/zh/domdocument.getelementbyid.php

Edit: didn't fully read the question. 编辑:没有完全阅读问题。

http://docs.php.net/manual/en/domelement.setattribute.php http://docs.php.net/manual/zh/domelement.setattribute.php

setAttribute("class", "already_booked");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用户输入验证,客户端还是服务器端? [PHP / JS] - User input validation, client-side or server-side? [PHP/JS] 与用户输入交互作为服务器端php和客户端更新的触发器? - interface with user input as trigger for server-side php and client side update? 服务器端用户输入验证 - 类设计* - server side user input validation - class design* 获取请求后的服务器端重定向 - Server-Side redirection after a fetch request Google登录,用户已经登录后如何在服务器端获取google userID? - Google sign in, How to get google userID server-side after user already signed in? 获取DIV的内容并保存到文件,jQuery / JS或服务器端 - Get the content of a DIV and save to a file, jQuery/JS or Server-side 使用服务器端脚本为autocomplete()检索输入值 - Retrieve input value with server-side script for autocomplete() 使用服务器端脚本过滤HTML输入元素的内容 - Filtering contents of an HTML input element using a server-side script 如何通过服务器端身份验证获取用户访问令牌 - How to get user access token though server-side authentication LinkedIn API - 验证用户是否已在服务器端登录 - LinkedIn API - Verify the user is logged in on server-side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM