I wrote a JavaScript script that swaps two selected img
tag src
values.
The point is to let the user rearrange a list of images.
For sending the new order to a PHP script, I have two ideas:
Have a button execute a JavaScript function that gathers the new order of images into an array of URLs. Then, rely on JavaScript to send the 开发者_如何学编程data to a PHP script?
Have the initial JavaScript rearrange
hidden
input tagvalue
attributes which would contain data such as a URL and order number. Then, rely on asubmit
input button to execute aPOST
request without JavaScript?
Thanks!
Why not consider using Jquery's UI Draggable/Sortable? It takes some of the brain damage out of the code and gives the user an intuitive way to interface with the reordering process:
http://jqueryui.com/demos/draggable/#sortable
You could then use the callbacks to update via Ajax, or set variables that could be dumped to PHP on submit.
精彩评论