duan4523 2010-01-20 01:18
浏览 41
已采纳

如何将这些javascript行从scriptaculous更改为jQuery语法

I am rewriting a helper class which was originally built on top of Scriptaculous. I am moving to jQuery - however, I am stuck on a couple of lines, that I need help with (see below): Note: the javascript code is interpersed with php variables (the sigils being a dead give away)

Statement 1

'new Insertion.Before(\'' . $updateContainer . '\', new Element(\'div\', {\'id\': \'' . $updateContainer . '_loading\', \'class\': \'' . $spinnerClass .'\'})); $(\'' . $updateContainer . '_loading\').innerHTML="<h4>Loading ...</h4>";',

Statement 2

'$(\'' . $updateContainer . '_loading\').remove();'
  • 写回答

1条回答 默认 最新

  • 普通网友 2010-01-20 01:42
    关注

    I'll assume that the $updateContainer is ID of the HTML element that contains the loading message.

    Then, I'd write the Statement 1 like this:

    $statement1 = sprintf('$(\'#%1$s\').html(\'<div id="%1$s_loading" class="%2$s"><h4>Loading</h4></div>\');', $updateContainer, $spinnerClass);
    

    And the second statement is:

    $statement2 = sprintf('$(\'#%s_loading\').remove();', $updateContainer);
    

    If you have a lot of AJAX communication and need the 'Loading' often, it might be better to hide() it so you can just show() it later instead of creating the HTML again.

    Statement1 would be uset to create the loading element, Statement2 with hide() instead of remove() to hide it and Statement3 with show() instead of hide() to show it again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度