0

我想知道一旦在 PHP 中存储信息,哪种方式更好、更有效。假设数据来自 PHP 变量,并最终将在 javascript 中使用:

  1. 立即存储为 js 变量,然后在函数中使用变量

    <script type="text/javascript">
           var information = "lots and lots and lots of text";
              // and then later use...
    

或者

2 .. 将其加载到 div 中,稍后使用 jquery '调用'它

 <div id="whatever" information="lots and lots and lots of text"></div>

只需使用 jquery 调用“信息”元素

一种方式更好吗?还是我在浪费时间调查这个?

4

2 回答 2

3

最快的方法是 js 变量。

它并没有说这是最好的方法,这取决于您的需求,但它是最快的。

于 2012-05-08T05:37:24.307 回答
1

我认为使用变量比使用 HTML 元素更有效。在 HTML 元素中存储信息将花费更多时间(我相信),因为它将解析 DOM以获取信息。变量可以直接访问。

于 2012-05-08T05:37:54.557 回答