Sun River
Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...
posts - 78,comments - 0,trackbacks - 0

 What are JavaScript types? - Number, String, Boolean, Function, Object, Null, Undefined.

  1. How do you convert numbers between different bases in JavaScript? - Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);
  2. What does isNaN function do? - Return true if the argument is not a number.
  3. What is negative infinity? - It’s a number in JavaScript, derived by dividing negative number by zero.

  4. What boolean operators does JavaScript support? - &&, || and !
  5. What does "1"+2+4 evaluate to? - Since 1 is a string, everything is a string, so the result is 124.
  6. How about 2+5+"8"? - Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.
  7. What looping structures are there in JavaScript? - for, while, do-while loops, but no foreach.
  8. How do you create a new object in JavaScript? - var obj = new Object(); or var obj = {};
  9. How do you assign object properties? - obj["age"] = 17 or obj.age = 17.
  10. What’s a way to append a value to an array? - arr[arr.length] = value;
  11. What is this keyword? - It refers to the current object.
posted @ 2009-03-10 11:37 Sun River| 编辑 收藏
     摘要:   阅读全文
posted @ 2009-03-10 11:36 Sun River| 编辑 收藏
 A SQL profile is sort of like gathering statistics on A QUERY - which involves many
tables, columns and the like....
In fact - it is just like gathering statistics for a query, it stores additional
information in the dictionary which the optimizer uses at optimization time to determine
the correct plan.  The SQL Profile is not "locking a plan in place", but rather giving
the optimizer yet more bits of information it can use to get the right plan.
posted @ 2009-01-28 11:14 Sun River| 编辑 收藏
<SCRIPT LANGUAGE="JavaScript1.3">
//Enter-listener
if (document.layers)
  document.captureEvents(Event.KEYDOWN);
  document.onkeydown =
    function (evt) {
      var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
      if (keyCode == 13)   //13 = the code for pressing ENTER

      {
         document.form.submit();
      }
    }
</SCRIPT>
posted @ 2008-04-23 12:11 Sun River| 编辑 收藏
 

My top javascripts

---. ExpandCollapse

 Used for expanding and collapsing block elements. I use this one for hiding divs or expanding the divs for forms. Very useful.

 function expandCollapse() {
for (var i=0; i<expandCollapse.arguments.length; i++) {
var element = document.getElementById(expandCollapse.arguments[i]);
element.style.display = (element.style.display == "none") ? "block" : "none";
 }
}
 
<p><em>Example:</em></p>
 <div id="on" style="border: 1px solid #90ee90;padding: 5px;">
   <a href="javascript: expandCollapse('expand', 'on');">Expand Layer</a>
 </div>
 <div id="expand" style="display: none;border: 1px solid #90ee90;padding: 5px;">
 <a href="javascript: expandCollapse('expand', 'on');">Collapse Layer</a>
 <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque eu ligula.   Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Ut wisi. Curabitur odio. Sed ornare arcu id diam. Integer ultricies, mauris venenatis vulputate pulvinar</p>
</div>

--Timer Layer

Used for hiding an element after ‘x’ of seconds. Great for hiding status messages after a person has submitted a form.

var timerID;
 
function ShowLayer(id)
{
 document.getElementById().style.display = "block"; 
}
 
function HideTimedLayer(id)
    clearTimeout(timerID);
    document.getElementById(id). »
         style.display = "none";
}
 
function timedLayer(id)
{
 setTimeout("HideTimedLayer(""" + id + """)",»
  5000); //5000= 5 seconds
}

--Form Checker

Probably one of the most useful scripts and there are several out there about form validation. This figures out what fields are required from the value in in a hidden input tag. Than it highlights the error areas.

for (var j=0; j<myForm.elements.length; j++) {
var myElement = myForm.elements[j];
var isNull = false;
if (myElement.name == field && myElement.»
style.display != "none") {
if (myElement.type == "select-one" || »
myElement.type == "select-multiple") {
if ((myElement.options[myElement.selectedIndex].
»value == null || myElement.
»options[myElement.
»selectedIndex].value == '') 
»&& errorString.indexOf(title) == -1) {
isNull = true;
}
} else if ((myElement.value == null || 
»myElement.value.search(/"w/)»
 == -1) && errorString.indexOf(title) == -1) {
isNull = true;
}
 
if (isNull) {
errorString += title + ", ";
if (document.getElementById('label_'+myElement.name))»
 { document.getElementById('label_'+myElement.name)
 ».className="er"; }
myElement.className="erInput";
} else {
if (document.getElementById('label_'+myElement.name)) {
document.getElementById('label_'+myElement.name)
».className="s1";
}
myElement.className="s1";
}
}
}
}
if (errorString != '') {
errorString = errorString.slice(0,errorString.length-2);
window.alert("Please fill in the following 
»required fields before submitting this form:"n"n"+errorString)
return false;
}
else {
return true;
}
}

---今天练习了一下用javascript做文字自动匹配的功能,类似于Google Suggest,当然人家Google是连接后台数据库,在网上不方便做连接数据库,所有功能在前台实现。在javascript里定义了一个全局数组arrCities用来存储一些城市的名字。然后当我们在文本输入框里输入某个城市名字的时候,每输入完一个字,就会拿当前的文字到arrCities数组里去比对,看是否存在于arrCities的某个成员里。若存在,就把该成员添加到紧靠文本输入框下面的组合列表框里,供我们选择,这样我们就不用完全输入完整个城市的名字,只要
从下面选择一个就可以完成想要做的工作。看下面的例子:

<html>
<head>
<title>Autosuggest Example</title>
<script type="text/javascript">
var arrCities=["
北京","上海"];
arrCities.sort();
//
控制是否显示层div1,bFlagtrue则表示显示div1,false则把div1从页面流里移除
function showDiv1(bFlag){
var oDiv=document.getElementById("div1");
if(bFlag){
oDiv.style.display="block";
}
else{
oDiv.style.display="none";
}
};
//
sel1添加option
function addOption(oListbox,sText){
var oOption=document.createElement("option");
oOption.appendChild(document.createTextNode(sText));
oListbox.appendChild(oOption);
};
//
移除一个option
function removeOption(oListbox,iIndex){
oListbox.remove(iIndex);
};
//
移除所有的option
function clearOptions(oListbox){
for(var i=oListbox.options.length-1;i>=0;i--){
removeOption(oListbox,i);
}
};
//
设置select里的第一个option被选中
function setFirstSelected(oListbox){
if(oListbox.options.length>0){
oListbox.options[0].selected=true;
}
}
//
获取匹配的字段
function getAutosuggestMatches(sText,arrValues){
var arrResult=new Array;
if(sText!=""){
for(var i=0;i<arrValues.length;i++){
if(arrValues[i].indexOf(sText)==0){
arrResult.push(arrValues[i]);
}
}
}
else{
showDiv1(false);
}
return arrResult;
};
//
把匹配的字段添加到sel1
function addSuggestOptions(oTextbox,arrValues,sListboxId,oEvent){
var oListbox=document.getElementById(sListboxId);
clearOptions(oListbox);
var arrMatches=getAutosuggestMatches(oTextbox.value,arrValues);
if(arrMatches.length>0){
showDiv1(true);
for(var i=0;i<arrMatches.length;i++){
addOption(oListbox,arrMatches[i]);
}
setFirstSelected(oListbox);
if(oEvent.keyCode==8){
oTextbox.focus();
}
else{
oListbox.focus();
}
}
};
//
获取select里的optiontextbox
function getSuggestText(oListbox,sTextboxId){
var oTextbox=document.getElementById(sTextboxId);
if(oListbox.selectedIndex>-1){

oTextbox.value=oListbox.options[oListbox.selectedIndex].text;
}
oTextbox.focus();
showDiv1(false);
}
//
通过Enter键确定选项
function getSuggestText2(oListbox,sTextboxId,oEvent){
if(oEvent.keyCode==13){
getSuggestText(oListbox,sTextboxId);
}
}
</script>
</head>
<body>
<p>
请输入一个城市的名字:</p>
<p>
<input type="text" id="txt1" value="" size="27"
onkeyup="addSuggestOptions(this,arrCities,'sel1',event)" /><br />
<div id="div1" style="background-color:white;display:none;">
<select id="sel1" style="width:202px" size="6"
onclick="getSuggestText(this,'txt1')" onkeyup="getSuggestText2(this,'txt1',event)">
</select>
</div>
</p>
</body>
</html>

用到的东西都比较基础,当然有很多细节性的东西需要注意。比如说用户选择完一个选项,要注意把组合列表框隐藏。所以这里把组合列表框放在了一个层上,隐藏和显示控制起来就方便一点。

--jsinnerHTMLinnerTextouterHTML的用法和区别

用法:
<div id="test">
<span style="color:red">test1</span> test2
</div><div id="test">
<span style="color:red">test1</span> test2
</div>

JS中可以使用:

test.innerHTML: 也就是从对象的起始位置到终止位置的全部内容,包括Html标签。
上例中的test.innerHTML的值也就是
<span style="color:red">test1</span> test2<span style="color:red">test1</span> test2

test.innerText: 从起始位置到终止位置的内容, 但它去除Html标签
上例中的text.innerTest的值也就是“test1 test2”, 其中span标签去除了。

test.outerHTML: 除了包含innerHTML的全部内容外, 还包含对象标签本身。
上例中的text.outerHTML的值也就是
<div id="test"><span style="color:red">test1</span> test2</div><div id="test"><span style="color:red">test1</span> test2</div>

完整示例:
<div id="test">
<span style="color:red">test1</span> test2
</div>

<a href="javascriptalert(test.innerHTML)">innerHTML内容</a>
<a href="javascript
alert(test.innerText)">inerHTML内容</a>
<a href="javascript
alert(test.outerHTML)">outerHTML内容</a><div id="test">
<span style="color:red">test1</span> test2
</div>

<a href="javascriptalert(test.innerHTML)">innerHTML内容</a>
<a href="javascript
alert(test.innerText)">inerHTML内容</a>
<a href="javascript
alert(test.outerHTML)">outerHTML内容</a>

特别说明:

innerHTML是符合W3C标准的属性,而innerText只适用于IE浏览器,因此,尽可能地去使用innerHTML,而少用innerText,如果要输出不含HTML标签的内容,可以使用innerHTML取得包含HTML标签的内容后,再用正则表达式去除HTML标签,下面是一个简单的符合W3C标准的示例:
<div id="test">
<span style="color:red">test1</span> test2
</div>
<a href="javascript
alert(document.getElementById('test').innerHTML.replace(/<.+?>/gim,''))">HTML,符合W3C标准</a>

 

--Javascript长文章分页

本例中实现用Javascript 长文章分页,Javascript 分页

<html>
<head>
<style type="text/css">
<!--
#jiax{
width:80%;/*
调整显示区的宽*/
height:200px;/*
调整显示区的高*/
font-size:14px;
line-height:180%;
border:1px solid #000000;
overflow-x:hidden;
overflow-y:hidden;
word-break:break-all;
}
a{
font-size:12px;
color:#000000;
text-decoration:underline;
}
a:hover{
font-size:12px;
color:#CC0000;
text-decoration:underline;
}
//-->
</style>
</head>
<body>
<div id="jiax">
本届都灵冬奥会,-------------------------------------------上届冬奥会,他们依然以13金傲视群雄。

</div>
<P>
<div id="pages" style="font-size:12px;"></div>
<script language="javascript">
<!--
var obj = document.getElementById("jiax");
var pages = document.getElementById("pages");
window.onload = function(){
var allpages = Math.ceil(parseInt(obj.scrollHeight)/parseInt(obj.offsetHeight));
pages.innerHTML = "<b>
"+allpages+"</b>";
for (var i=1;i<=allpages;i++){
pages.innerHTML += "<a href=""javascript
showpart('"+i+"');"">"+i+"</a>&nbsp;";

}
}
function showpart(x){
obj.scrollTop=(x-1)*parseInt(obj.offsetHeight);
}
//-->
</script>
</body>
</html>

--js实现selectdiv的隐藏与显示

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>
无标题文档</title>
</head>

<body>

<script type="text/javascript">
function change(a){
var xxx = document.getElementById("xxx");
var divArray = xxx.getElementsByTagName("div");
for (var i=0;i<divArray.length;i++) {
if (divArray[i].id == a) {
divArray[i].style.display='';
}else {
divArray[i].style.display='none';
}
}
}
</script>

<div id=xxx>


<div id=aaa>
<h1>aa</h1>
aaaa
</div>
<div id=bbb style="display:none ">
bbbb
</div>
<div id=ccc style="display:none ">
cccc
</div>

</div>

<select onChange="change(this.value)">
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="ccc">ccc</option>
</select>
</body>
</html>

---++日期减去天数等于第二个日期
<script language=Javascript>
function cc(dd,dadd)
{
//
可以加上错误处理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "
" + (a.getMonth() + 1) + "" + a.getDate() + "")
}
cc("12/23/2002",2)
</script>

++++检查一段字符串是否全由数字组成
<script language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>

+++++++++++++

--js处理输出分页(完美版)

head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>
无标题文档</title>
<style type="text/css">
<!--
div{font-size:14px;}
-->
</style>
</head>

<body>
<textarea name="" cols="" rows="" id="conpage" style="display:none;">
<!--pages-->
你好
<!--pages-->
我好
<!--pages-->
他也好
<!--pages-->
全都好
<!--pages-->
</textarea>
<script language="javascript">
var zhenze = /[^0-9]/;//
创建正则,表明非数字字符串
var thispage = document.getElementById("conpage").value;//
取得内容
var page_amount,x;
page_amount = thispage.split('<!--pages-->').length;
page_amount--;//
内容里的pages个数
var asarray = new Array();//
数组
var v=0;
for(var t=0;t<page_amount;t++){
asarray[t] = thispage.indexOf("<!--pages-->",v);//
记录每个pages的位置
v=asarray[t];
v++;
};
page_amount--;
for(var s=0;s<page_amount;s++){
//
以下是分段写出所有内容
document.write('<div id="pg'+(s+1)+'" style="block">');
document.write(thispage.substring(asarray[s],asarray[s+1]));
document.write('</div>');
alert(s+1);
};


var obj,objt;
var s_a_d = 1;//
记录当前显示的页数id,默认为第1页显示,当设用showpage时,此变量用于记录上次所显示的页码,
function hidpage(hidt){//
此函数用于隐藏页数
obj=eval("document.getElementById('pg"+hidt+"')");
obj.style.display = "none";
};

function showpage(sow){//
此函数用于显示页数
obj = eval("document.getElementById('pg"+sow+"')");
objt = eval("document.getElementById('pg"+(s_a_d)+"')");//
此句是取得上次显示的页码
objt.style.display = "none";//
先隐藏上次显示的页码
obj.style.display = "block";//
再显示当前用户需要显示的页码
s_a_d = sow;
document.getElementById("pageamo").value = sow;
alert("
当前显示第"+s_a_d+"");
};

var tts;
function goto(){ //
页面转向函数,作用是用户在文本框里输入页码然后转向
tts = document.getElementById("inputpage").value;
if(!tts.match(zhenze)==""){
alert("
错误,你输入了非数字类型字符");
return;
};
if(tts>page_amount || tts < 1){
alert("
无此页");//非法输入全部检验完毕
}else{
showpage(tts);//
合法的执行转向
};
};


document.write('<div>');
document.write('
你现在在第<input type="button" id="pageamo" value="'+s_a_d+'" style="font-size:12px;height:18px;background-color:#FFFFFF; color:red;font-weight:bold;border:#FFFFFF 0px solid;"> ');//标示当前页码
document.write('
共有'+page_amount+'');//总页数
for(var k=0;k<page_amount;k++){
document.write(' <a href="javascript
showpage('+(k+1)+')" style="text-decoration:none;">');
document.write(" ["+(k+1)+"] ");
document.write('</a> ');
hidpage(k+1);//
隐藏所有页数
};//for
写出页码 : 1 2 3 4 5 ....
showpage(1);//
首先显示第一页内容
document.write('
转到第 <input type="text" id="inputpage" style="width:20px;font-size:12px;height:18px;" value=""> ');//转向表单
document.write('<input type="button" value=" Go " onclick="goto()" style="height:20px;">');
document.write('</div>');
</script>
</body>
</html>

posted @ 2008-02-22 22:13 Sun River| 编辑 收藏
 

Javascript Table filter

This is a simple but powerful javascript to filter a standard html table. The user enters a term in a text field and just the table entries which contain it will be shown.

function filter (term, _id, cellNr){
               var suche = term.value.toLowerCase();
               var table = document.getElementById(_id);
               var ele;
               for (var r = 1; r < table.rows.length; r++){
                               ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g,"");
                               if (ele.toLowerCase().indexOf(suche)>=0 )
                                              table.rows[r].style.display = '';
                               else table.rows[r].style.display = 'none';
               }
}

This function searches in the table with the id defined by _id in every row in the cell defined by cellNr. The search is case insensitive.
The usage is straightforward:

<form>
               <input name="filter" onkeyup="filter(this, 'sf', 1)" type="text">
</form>

It should work with all modern browsers, e.g. IE5, Firefox 1.0, Opera 7 and Mozilla 1.0.

Since many people have asked for another version of the script which

  • searches in every cell of a row
  • searches for more than one keyword (using AND)

I have made another version of the script:

function filter2 (phrase, _id){
               var words = phrase.value.toLowerCase().split(" ");
               var table = document.getElementById(_id);
               var ele;
               for (var r = 1; r < table.rows.length; r++){
                               ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
                       var displayStyle = 'none';
                       for (var i = 0; i < words.length; i++) {
                                   if (ele.toLowerCase().indexOf(words[i])>=0)
                                              displayStyle = '';
                                  else {
                                              displayStyle = 'none';
                                              break;
                                   }
                       }
                               table.rows[r].style.display = displayStyle;
               }
}

Web designers must always keep usability in mind when designing web sites. A site must allow quick and easy access to information during the very short time that a site first holds a visitor's interest. Any confusion that ensues about where things are, and that person's business is gone. Providing a way to precisely search for what they need is an excellent way to provide that usability. What Chris Root explains in this article is a way for your visitors to find and select items contained in long lists. He will also suggest ways to expand this to searching within HTML or XML documents.

Auto-Complete

Many desktop applications have user interface controls that allow a user to find matches for things as they type. This feature can be very useful for long lists of items such as states, countries, streets or product categories. Many web browsers implement this sort of functionality in their address bars. As you type, web site address matches that are part of a list of recently visited sites appear in a menu below the address bar. This reduces the amount of time it takes to access information.

Another place this is implemented is in HTML select menus. Unfortunately this only works with the first letter typed, it is not implemented in all browsers on all platforms and it doesn't shorten the list of choices to only matches.

The script described in this article will allow a user to begin typing what they are looking for in a text box while a select menu updates itself with matches. In the example the list comes from the contents of the select menu but it can also come from other sources.

The HTML

The HTML for this project is pretty simple. You could however use this script several places in a large form with multiple lists of information with no trouble. This example uses a list of city streets.

<body onLoad="fillit(sel,entry)">
<div>Enter the first three letters of a street and select a match from the menu.</div>
<form><label>
Street
<input type="text" name="Street" id="entry" onKeyUp="findIt(sel,this)"><br>
  <select id="sel">
        <option value="s0001">Adams</option>
        <option value="s0002">Alder</option>
        <option value="s0003">Banner</option>
        <option value="s0004">Birchtree</option>
        <option value="s0005">Brook</option>
        <option value="s0007">Cooper</option>
<!--and so on and so forth-->
  </select></label>
</form>
</body>
</html>

When the text box registers a keyUp event, the find() function calls and passes two parameters, the id of the select menu and a reference to the text field.

For something like state information, allow the user the choice of using the auto-complete script or just selecting something from the menu, especially if they know the item they wish to select is at the top of the list. If someone lives in Alabama for instance, there is no need to have them enter the first three letters of their state when the item they want is at the top of the list of states. Fill the select menu (a list box can be used as well) with all the values and text labels that you want your user to choose from in the HTML code to start with.

Alternatively, depending on the information in the list, the choice may not be as obvious. In this case you could store it in an array only and the user would always need to select a match. If there was only one match, and that match was the correct one, they could leave the menu alone. Otherwise they would need to select from the available matches displayed in the menu.

The longer the list the more useful our script becomes. It has been tested with a list over 1000 city streets and had an acceptable performance, even on a not so modern machine. There is a minimum of two characters before a search will start. this helps reduce the number of matches shown after any given keystroke. This limit can be adjusted easily.

When the page loads, a function called fillit() is called.

//initialize some global variables
var list = null;;
function fillit(sel,fld)
{
        var field = document.getElementByid(fld);
        var selobj = document.getElementById(sel);
        if(!list)
        {
                ar len = selobj.options.length;
                field.value = "";
                list = new Array();
                for(var i = 0;i < len;i++)
                {
                        list[i] = new Object();
                        list[i]["text"] = selobj.options[i].text;
                        list[i]["value"] = selobj.options[i].value;
                }
        }
        else
        {
            var op = document.createElement("option");
            var tmp = null;
            for(var i = 0;i < list.length;i++)
           {
                tmp = op.cloneNode(true);
                tmp.appendChild(document.createTextNode(list[i]["text"]));
                tmp.setAttribute("value",list[i]["value"]);
                selobj.appendChild(tmp)/*;*/
           }
        }
}

A global variable is initialized to null. This will hold an array that in turn holds two custom objects to hold our data. We then get a reference to our select menu and text field objects. If our array does not exist yet (the page has just loaded so it’s still null), then we get the number of options in our select menu, set the contents of the text field to empty and begin looping through the menu contents.

As we run through each menu option, an object is created that will hold both what is in the value attribute and the text of the option tag.

If however our list array already exists, we are calling the function in order to refill the menu with all the original data. An option element is created and a temporary container is initialized.

In the loop the select menu is reconstructed using DOM methods.

Finding a Match

The findIt() function does the searching. It accepts two arguments. The first is the name of the select menu, the second is the name of the text field.

function findit(sel,field)
{
        var selobj = document.getElementById(sel);
        var d = document.getElementById("display");
        var len = list.length;
        if(field.value.length > 2)
        {
                if(!list)
                {
                        fillit(sel,field);
                }
                var op = document.createElement("option");
                selobj.options.length = 1
                var reg = new RegExp(field.value,"i");
                var tmp = null;
                var count = 0;
                var msg = "";
                for(var i = 0;i < len;i++)
                {
                        if(reg.test(list[i].text))
                        {
                                d.childNodes[0].nodeValue = msg;
                                tmp = op.cloneNode(true);
                                tmp.setAttribute("value",list[i].value);
                                tmp.appendChild(document.createTextNode(list[i].text));
                                selobj.appendChild(tmp);
                        }
                } 
        }
        else if(list && len > selobj.options.length)
        {
                selobj.selectedIndex = 0;
                fillit(sel,field);
        }
}

The first step is to get references to the select menu and the text field. We also need the length of the list array.

If the number of characters in the text field is greater than 2 and the list array exists. Then the menu is cleared of it's content to prepare it for display of any matches. The number of options is set to one rather than 0 to allow for an option that is always there such as a “Select a Street” option.

A regular expression object is then created that will be used to look for a match at the beginning of a given string. Using this object to create a regular expression allows the use of a string from whatever source we wish to be used along with any regular expression characters. The first parameter in the object constructor is the regular expression the second is any flags such as "i" for making the search case insensitive. If you were searching something other than one or two word street names, state names or country names you would want to match the beginning of word boundaries using ""b" instead of "^".

A few utility variables are initialized and we then loop through each of the list items contained in the arrays. If there is a match, the values are used to fill a new copy of the option element we created before the loop started. One thing to note about setting the properties of option elements is that the text label of an option is not an attribute. You must use the optionelement.text syntax rather than setAttribute to set the text label for each option.

If the length of the text in the field is less than 2 characters then we need to determine if the list needs to be refilled with all the values. By doing this, you allow the user to give up on their search before typing more than two characters and manually select something from the menu if they wish. If the user selects the text in the field and clears it to start a new search this will trigger that action. The fillit function is called and the select menu is refilled.

Possible Mods

To make this script and user interface more like the auto-complete widget in a browser address bar, you could use a DHTML menu and provide keyboard control for selecting a match and updating the content in the text box with the selected match.

This script would allow searching in any array of information and with a little modification any HTML collection. Searchable FAQ's, API documentation or help systems could be achieved by searching content contained in a hidden IFrame, the main HTML document itself or an XML document loaded in the background using the HTTPRequest object.

Conclusion

As you can see using auto-complete widgets on a web site can allow a visitor quick access to information. Always be on the lookout for ways to improve the user experience for your visitors and they will continue to come back for more.

posted @ 2008-02-22 22:12 Sun River| 编辑 收藏
     摘要:   9 Javascript(s) you better not miss !! ...  阅读全文
posted @ 2008-02-22 22:10 Sun River| 编辑 收藏
http://www.dojoforum.com/taxonomy/term/8
http://www.dojoforum.com/
posted @ 2008-02-19 13:50 Sun River| 编辑 收藏
from : http://www.demay-fr.net:8080/Wicket-start/app

package wicket.contrib.dojo.examples;

import java.util.ArrayList;
import java.util.Iterator;

import wicket.PageParameters;
import wicket.contrib.dojo.html.list.lazy.DojoLazyLoadingListContainer;
import wicket.contrib.dojo.html.list.lazy.DojoLazyLoadingRefreshingView;
import wicket.extensions.markup.html.repeater.refreshing.Item;
import wicket.markup.html.WebPage;
import wicket.markup.html.basic.Label;

public class LazyTableSample extends WebPage {

public LazyTableSample(PageParameters parameters){
DojoLazyLoadingListContainer container = new DojoLazyLoadingListContainer(this, "container", 3000)
DojoLazyLoadingRefreshingView list = new DojoLazyLoadingRefreshingView(container, "table"){

@Override
public Iterator iterator(int first, int count) {
ArrayList<String> list = new ArrayList<String>();
int i = 0;
while(i < count){
list.add("foo" + (first + i++));
}

//fake a busy and slow machine
int j = 0;
while (j < 1000000000){j++;}

return list.iterator();
}

@Override
protected void populateItem(Item item) {
new Label(item, "label",item.getModel());
}

};
}
}

posted @ 2008-02-19 13:45 Sun River| 编辑 收藏
     摘要:   Dojo API略解续 dojo.lang.string dojo.string.substituteParams 类似C#中的String.Format函数 %{name}要保...  阅读全文
posted @ 2008-02-19 11:30 Sun River| 编辑 收藏
仅列出标题
共8页: 上一页 1 2 3 4 5 6 7 8 下一页