用于交换HTML代码的Javascript或PHP [英] Javascript or PHP for swapping HTML Code

查看:75
本文介绍了用于交换HTML代码的Javascript或PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在刷新或页面加载时交换HTML代码/项目。



我的页面有多个HTML项目,例如。



项目1

项目2

项目3

......

项目10



当我刷新页面时它应该交换项目如



项目3

项目2

项目10

......

项目1





我的列表是HTML格式我没有使用任何数据库或编程。

I want to swap HTML Code/Items on refresh or page load.

My page has multiple HTML items like.

Item 1
Item 2
Item 3
......
Item 10

when I refresh the page it should swap the items like

Item 3
Item 2
Item 10
......
Item 1


My listings are in HTML I am not using any database or programming.

推荐答案

要通过php交换代码需要返回服务器(例如通过AJAX) 。由于您指定服务器上没有数据库(与此相关),我认为您还意味着没有文本文件或任何其他用作数据源的数据。



说到这里,您需要的一切都在客户端,因此您应该使用javaScript来完成工作。



至于那个,你'有两种主要方法,根据HTML元素的类型选择更好的方法:

To swap the code via php would require a trip back to the server (such as via AJAX). Since you specify you've no database on the server (related to this), I'll presume you also mean no text files or anything else that's used as a data source.

With that being said, everything you need is on the client and therefore you should be using javaScript to do the work.

As for even that, you've two primary approaches, the better one to select depending upon the types of HTML elements these are:


  1. 交换值
  2. 交换位置





有人可能会将此细微之处转移到其他级别,例如捕获和替换'innerHTML',但这是明智之举处理这个。



(顺便说一下:当我有选择时,我更喜欢php到javaScript - 它更有趣)。




这篇关于用于交换HTML代码的Javascript或PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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