Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21219
  • 博文数量: 8
  • 博客积分: 370
  • 博客等级: 一等列兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 17:52
文章分类

全部博文(8)

文章存档

2009年(2)

2008年(6)

我的朋友

分类:

2009-08-05 16:33:29

使用prototype的Ajax.Updater更新带javascript的html

关键字: prototype Ajax.Updater evalScripts javascript html js

prototype的Ajax.Updater可以用来更新一段html,但在更新带javascript的html时,需要注意几个问题

. 需要在Ajax.Updater添加参数 evalScripts : true

. javascript代码块要使用下面的形式
showHi = function() {
    alert('Hi');
}

而不能使用下面的形式
function showHi() {
    alert('Hi');
}

. 注意javascript代码块中不能使用 标记,否则 IE 会出错,firefox没问题。

下面是个例子, 在a1.jsp中加载a2.jsp,

 a1.jsp代码
  1. <html>  
  2. <head>  
  3. <title>Insert title heretitle>  
  4. <script type="text/javascript" src="prototype-150.js">script>  
  5. <script type="text/javascript">  
  6. function ajax() {   
  7.     var url = "/MyWebApp/a2.jsp";   
  8.     var myajax = new Ajax.Updater(   
  9.         {success: 'mydiv'},    
  10.         url,   
  11.         {   
  12.             asynchronous:true,   
  13.             method: 'get',   
  14.             evalScripts:true   
  15.         }   
  16.     );   
  17. }   
  18. script>  
  19. head>  
  20. <body>  
  21.     <a href="#" onclick="ajax()">click here1a>  
  22.   
  23.     <div id="mydiv">div>  
  24. body>  
  25. html>  

 

 a2.jsp代码
  1. <script type="text/javascript">  
  2.     showHi = function() {   
  3.         alert('Hi');   
  4.     }   
  5.     sayHello = function() {   
  6.         alert('Hello');   
  7.     }   
  8. script>  
  9.   
  10. <a href="#" onclick="showHi();">showHia>  
  11.   
  12. <script type="text/javascript">  
  13. sayHello();   
  14. script>  

 参考

阅读(592) | 评论(0) | 转发(0) |
0

上一篇:Firefox中安装Firebug插件

下一篇:没有了

给主人留下些什么吧!~~