??xml version="1.0" encoding="utf-8" standalone="yes"?>
It's ease to use.And tutorial is HERE:http://www.svendtofte.com/code/learning_venkman/index.php
文章来源:http://blueoxygen.dflying.net/3/archive/75_ajax_tool_box---venkman.html
]]>See DFlying's finding:
Yep,No Block Scope concept in JavaScript.Only the global and function Scope.You can use "var" to declare a global variable and use "var" agian to declare a homonymous variable in a function.In the function ,the second one works.But there is no Block scope.
Check the codes below,it's a demo for "NO BLOCK SCOPE"
function test(o) {var i = 0; // i is defined throughout functionif (typeof o == "object") {var j = 0; // j is defined everywhere, not just blockfor(var k = 0; k < 10; k++) { // k is defined everywhere, not just loopdocument.write(k);
}document.write(k); // k is still defined: prints 10}document.write(j); // j is defined, but may not be initialized}
But,You still need to care javascript's FUNCTION SCOPE.Also see code snippet:
var scope = "global";
function f( ) {alert(scope); // Displays "undefined", not "global"var scope = "local"; // Variable initialized here, but defined everywherealert(scope); // Displays "local"}f( );
Right,thought you alert(scope) first and then define a new functin scope variable scope.However,once you define a function scope vriable,it will hide the global variable in the function body,whatever the definition order.
AutoAssist is an auto completion web widget that written in pure JavaScript. It can help enhance the accessibility of existing website, let the users to work effective and feel comfortable. AutoAssist Javascript only and is built upon prototype and rico. Its main features are :
* improve the User Experience
* Don't require an Ajax experience
* pretty managed JavaScript, easy to understand and customize
* works well on Mozilla/FireFox, IE and Opera
* have a nice solution for fast user typing, reduce a lot of corresponding server loading (20% - 80% *)
The code for the screenshot is very simple :
var foo = function() {
var tt = new AutoAssist("t", {setRequestOptions: function() {
var pars = "name=" + this.txtBox.value;
return { url: "/country.php", parameters: pars };
}});
}
Event.observe(window, "load", foo);
You can find a ten minutes tutorial for AutoAssist explaining in details how to use this script to create an auto-complete list based on country data.
By the way,script.aculo.us also has it's impelmention:http://demo.script.aculo.us/ajax/autocompleter
目前比较公认的有三种数据传输交互方式QXHTML Fragment,JSON,XML。当然也有不同的声音Q这里也会介l?/P>
q是一个Struts的例子,Action中response直接flush输出。当然也可以让Struts导向到结果jsp面Q请求的XHR可以得到jsp生成的HTML内容?BR>~点是:当返回有Form的内容的时候会崩溃。CSS样式讄复杂?/P>
XML在很多AJAXCZ当中作ؓ数据传递的标准。而XMLh很好的数据语义描q性,服务器端生成方式众多Q而几乎所有浏览器都支持对XML 的解析。以JavaScript解析服务器端q回的XMLZ子,只需要XHR的responseXML属性即可获得XML由javascript解析 (L我在BlogJAVA写的操作CZ) 而XML的生方式似乎所有h都认准了
一c,gq样子语义描q更清楚。但是我从michael那里得到启示Q确实,用此cL式传输数据几乎无法在客户端统一处理。从我的showcase中大家也可以看到QJavascript解析XML后更新DOM直就是体力活Q枯燥且Ҏ出错Q而此UXMLq回的数据则会千差万别,以寻扄定tag的节点的方式怎么能统一处理呢?于是Q第二种XML传输方式应运而生?/P>
q样子只要客L和服务器端达成共识string long int{代表的数据cd可以在两端q原成自己可用的对象。而这也是micheal认ؓ真正的AJAX应该有的形态,其中AJAX引擎便承担v了这份工作?BR>~点QXML的构造和解析在没有类库辅助的情Ş下是一个灾难,而XML文g的传输效率似乎也不如单的文本高。我讲会在后面的blog中提及XML文g的生方法,以及客户端一些解析的框架?/P>
JSON是JavaScript Object Notation的羃写,是一份规范,定义了极其简单的数据描述形式。几乎在所有主语a上都有实现。JSON对象是名/值对的集合,所以一个简单的JSON对象为:
var testObj={
"name" : david,
"sex" : Male,
"work" : SE
}
客户端javascript调用eval()可以解析由服务器端产生的JSON丌Ӏvar jsonExpression =
( + req.responseText + );
var customer = eval(jsonExpression);
而服务器?JAVA)也有相应的lib来操作:JSONObject 的toString()
~点Q虽然JSONz高效,但是转化为Javascript对象通过eval()也就是说QAJAX的传输邦定在了JSON上面Q这PM让h不很攑ֿ。ƈ且JSON对象难于阅读与理解,不如XML直观?/P>
除了会在下一AJAX的blog介绍JAVA对象序列化到XML以外Q会一些从头开始构建应用的例子Q其中不会用buffalo DWR一cȝ框架Q我会尝试选用不同的方案作为数据传输方式供大家参考?/P>
<div id="image_16209134_normal">
<script language="Javascript">
photo_hash['16209134'] = new Object();
photo_hash['16209134'].title = '2am on Saturday';
</script>
<h4 id="title_div16209134"
style="margin-bottom: 0px; margin-top: 0px;">
2am on Saturday
</h4>
<script type="text/javascript">
initPhotosUserPageTitle_div('16209134');</script>
q是Flickr上面一D代码。确实,它得代码阅读v来结构不清晰了。Behavior应用之后Q不需在元素上写明触发事g要执行的ҎQ比?BR><a onclick="this.parentNode.removeChild(this)" href="#">
Click me to delete me
</a>
而变成了
<ul id="example">
<li>
<a href="/someurl">Click me to delete me</a>
</li>
</ul>
那么javascript如果扑ֈq个a链接q加上onclick事gҎ的呢Q采用css selector
var myrules = {
'#example li' : function(el){
el.onclick = function(){
this.parentNode.removeChild(this);
} }};
Behaviour.register(myrules);
实看v来,html清爽了,但是Q却引入了其他的元素。okQ我们可以ؓ每个控g定义idQ其实也未尝不可Qasp.net不也是web component开发的时候都定义id的么Q可g又脱裤子攑ֱ之嫌。在l护一个对某一l应用相同样式或响应
相同Ҏ的html控g上应用behaviorQ有意义Qv码不必每个上面都写上onclick之类的,但是对于更普遍的应用Q每个html控g要做得事情是不同的啊。那个时候,不但用behavior代码量增加了Q而且l护一个var myrules里的内容和去删除控g上的onclick其实工作量差不多。真正的应用可不是demo啊,列出来一排link写着remove meQ然后执行一L动作?
不过正如我上面说的,q是有一定的应用场景的,大家可以在有此需求的时候考虑Q还有一Behaviour.js