2010年5月26日 星期三

window onload 的幾種寫法


window.onload=function(){
 call_block();
}

ASP.NET如何輸出刷新父窗口腳本語句
1.  this.response.write("<script>opener.location.reload();</script>"); 


2.  this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>");  

3.  Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的頁.asp'');</script>")




//如何刷新包含該框架的頁面用   
<script language=JavaScript>
  parent.location.reload();
</script>  

//子窗口刷新父窗口
<script language=JavaScript>
   self.opener.location.reload();
</script>

( 或 <a href="javascript:opener.location.reload()">刷新</a>   )

//如何刷新另一個框架的頁面用   
<script language=JavaScript>
  parent.另一FrameID.location.reload();
</script>


<body onload="opener.location.reload()">
開窗時刷新
<body onUnload="opener.location.reload()">
關閉時刷新

<script language="javascript">
window.opener.document.location.reload()
</script>

如果直接把新動作附在 window.onload 的話,是會把前一個 window.onload 的動作給蓋掉的




所以建議這樣做






var oldOnload = window.onload || function () {};

window.onload = function () {
oldOnload();
// Do What Tou Want..
}



把舊的 window.onload 設定成一個變數,
然後在新的 window.onload 裡呼叫它

2010年5月23日 星期日

FORM裡的預設值

  1. <form name="update_data" action="update_data.php">   
  2. 暱名:<input type="text" name="nick" value="<?=$nick?>">   
  3. 興趣:   
  4. <input type="checkbox" name="ints[]" value="動畫">動畫   
  5. <input type="checkbox" name="ints[]" value="閱讀">閱讀   
  6. <input type="checkbox" name="ints[]" value="電影">電影   
  7. <input type="checkbox" name="ints[]" value="漫畫">漫畫   
  8. <input type="checkbox" name="ints[]" value="籃球">籃球   
  9. <input type="checkbox" name="ints[]" value="健走">健走   
  10. <input type="submit" value="送出修改">   
  11. </form>   
  12. <script>   
  13. var checkvalue = "<?=$ints?>";   
  14. var theform = document.update_data.elements;   
  15. for(i=0;i<theform.length;i++) {   
  16.   //迴圈檢查型別為checkbox且名稱為ints[]的項目,是否有興趣值符合   
  17.   if(theform[i].type == "checkbox" && theform[i].name.indexOf('ints[]')!= "-1" && checkvalue.indexOf(theform[i].value)!=-1){   
  18.     theform[i].checked = true;   
  19.   }   
  20. }   
  21. </script>  


舊式寫法

  1. <form name="update_data" action="update_data.php">   
  2. 暱名:<input type="text" name="nick" value="<?=$nick?>">   
  3. 興趣:   
  4. <input type="checkbox" name="ints[]" value="動畫" <?php if(strpos($ints,'動畫')!==false) echo 'checked'?>>動畫   
  5. <input type="checkbox" name="ints[]" value="閱讀" <?php if(strpos($ints,'閱讀')!==false) echo 'checked'?>>閱讀   
  6. <input type="checkbox" name="ints[]" value="電影" <?php if(strpos($ints,'電影')!==false) echo 'checked'?>>電影   
  7. <input type="checkbox" name="ints[]" value="漫畫" <?php if(strpos($ints,'漫畫')!==false) echo 'checked'?>>漫畫   
  8. <input type="checkbox" name="ints[]" value="籃球" <?php if(strpos($ints,'籃球')!==false) echo 'checked'?>>籃球   
  9. <input type="checkbox" name="ints[]" value="健走" <?php if(strpos($ints,'健走')!==false) echo 'checked'?>>健走   
  10. <input type="submit" value="送出修改">   
  11. </form>  

 

  1. <?php $test = 'B'; ?>   
  2. <form name="test1">   
  3. <select name="test2">   
  4. <option value="A">A</option>   
  5. <option value="B">B</option>   
  6. <option value="C">C</option>   
  7. </select>   
  8. </form>   
  9. <script>document.test1.test2.value = '<?=$test?>';</script>  

沒注意到的Select 功能

optgroup 沒用過,下次試試看!!

multiple 多選!!
 
<form name='sel'>
<select name='stars' multiple style='width:180px'
  onchange='alert( this.selectedIndex )'>
<optgroup label='牛排'>
<option>三分熟
<option>七分熟
</optgroup>
<optgroup label='雞排'>
<option >大塊
<option >小塊
</optgroup>
</select>
</form>由http://goodlucky.pixnet.net/blog/post/27026120 看到好的範例

 1判斷select選項中 是否存在Value="paraValue"Item

 2select選項中 加入一個Item

 3select選項中 刪除一個Item

 4刪除select中選中的項

 5修改select選項中 value="paraValue"text"paraText"

 6設置selecttext="paraText"的第一個Item為選中

 7設置selectvalue="paraValue"Item為選中

 8得到select的當前選中項的value

 9得到select的當前選中項的text

10得到select的當前選中項的Index

11清空select的項

  

 

js 代碼

// 1.判斷select選項中是否存在Value="paraValue"Item

function jsSelectIsExitItem(objSelect, objItemValue) {

var isExit = false;

for (var i = 0; i < objSelect.options.length; i++) {

if (objSelect.options[i].value == objItemValue) {

isExit = true;

break;

}

}

return isExit;

}

 

// 2.select選項中加入一個Item

function jsAddItemToSelect(objSelect, objItemText, objItemValue) {

//判斷是否存在

if (jsSelectIsExitItem(objSelect, objItemValue)) {

alert("ItemValue值已經存在");

} else {

var varItem = new Option(objItemText, objItemValue); 

objSelect.options.add(varItem);

alert("成功加入");

}

}

 

// 3.select選項中刪除一個Item

function jsRemoveItemFromSelect(objSelect, objItemValue) {

//判斷是否存在

if (jsSelectIsExitItem(objSelect, objItemValue)) {

for (var i = 0; i < objSelect.options.length; i++) {

if (objSelect.options[i].value == objItemValue) {

objSelect.options.remove(i);

break;

}

}

alert("成功刪除");

} else {

alert("select中 不存在該項");

}

}

 

 

// 4.刪除select中選中的項

function jsRemoveSelectedItemFromSelect(objSelect) {

var length = objSelect.options.length - 1;

for(var i = length; i >= 0; i--){

if(objSelect[i].selected == true){

objSelect.options[i] = null;

}

}

} 

 

// 5.修改select選項中 value="paraValue"text"paraText"

function jsUpdateItemToSelect(objSelect, objItemText, objItemValue) {

//判斷是否存在

if (jsSelectIsExitItem(objSelect, objItemValue)) {

for (var i = 0; i < objSelect.options.length; i++) {

if (objSelect.options[i].value == objItemValue) {

objSelect.options[i].text = objItemText;

break;

}

}

alert("成功修改");

} else {

alert("select中 不存在該項");

}

}

 

// 6.設置selecttext="paraText"的第一個Item為選中

function jsSelectItemByValue(objSelect, objItemText) {

//判斷是否存在

var isExit = false;

for (var i = 0; i < objSelect.options.length; i++) {

if (objSelect.options[i].text == objItemText) {

objSelect.options[i].selected = true;

isExit = true;

break;

}

} 

//Show出結果

if (isExit) {

alert("成功選中");

} else {

alert("select中 不存在該項");

}

}

 

// 7.設置selectvalue="paraValue"Item為選中

document.all.objSelect.value = objItemValue;

 

// 8.得到select的當前選中項的value

var currSelectValue = document.all.objSelect.value;

 

// 9.得到select的當前選中項的text

var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;

 

// 10.得到select的當前選中項的Index

var currSelectIndex = document.all.objSelect.selectedIndex;

 

// 11.清空select的項

document.all.objSelect.options.length = 0;

2010年5月20日 星期四

FORM下停止/啟用enter觸發submit

不讓Enter起作用:
在要輸入的text中加入

<input type=”text” onKeyPress=”return FormEnterKey(event)”>

然後

<script language="JavaScript">

function FormEnterKey(e)
{
     var key;     
     if(window.event)
          key = window.event.keyCode; 
     else
          key = e.which;  

     return (key != 13);
}

</script>

讓Enter作用

<form> TEXT: <input name=text1 type=text onKeyPress="return SubmitEnter(this,event)"><BR> <input TYPE=submit value="登入"> </form>










<SCRIPT TYPE="text/javascript"> <!-- function SubmitEnter(myform,e) { var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true; if (keycode == 13) { myform.form.submit(); return false; } else return true; } //--> </SCRIPT>


2010年5月15日 星期六

加入CODE的高亮度顯示

這是一套由 Google 所推出Google Code Prettify

可以由此下載http://google-code-prettify.googlecode.com/files/prettify-small-5-Jul-2008.zip

或是由GOOGLE載入
<script type="text/javascript" src="http://jsgears.googlecode.com/svn/trunk/prettify.min/prettify.js"></script>


要載入的東西
<link href="prettify.css" type="text/css" rel="stylesheet" />  <script type="text/javascript" src="prettify.js"></script>

使用上
<pre class=prettyprint>
中間為程式碼,須先經由htmlspecialchars轉換
</pre>

最後在 body 內加上
<body onload="prettyPrint()">

若是不能在body onload 
<script type="text/javascript">
var oldonload = window.onload;
if (typeof window.onload != 'function') {
  window.onload = prettyPrint;
}
else {
  window.onload = function() {
    oldonload();
    prettyPrint();
  }
}
</script>

2010年5月11日 星期二

ULTRA EDIT 的正規搜尋

Regular Expressions in UltraEdit
UltraEdit SymbolUNIX SymbolFunction
%^Matches/anchors the beginning of line.
$$Matches/anchors the end of line.
?.Matches any single character except a newline character. Does not match repeated newlines.
* Matches any number of occurrences of any character except newline.
++Matches one or more of the preceding character/expression. At least one occurrence of the character must be found. Does not match repeated newlines.
++*Matches the preceding character/expression zero or more times. Does not match repeated newlines.
^\Indicates the next character has a special meaning. "n" on its own matches the character "n". "^n" (UE expressions) or "\n" (UNIX expressions) matches a linefeed or newline character. See examples below.
[ ][ ]Matches any single character or range in the brackets.
[~xyz][^xyz]A negative character set. Matches any characters NOT between brackets.
^b\fMatches a page break/form feed character.
^p\pMatches a newline (CR/LF) (paragraph) (DOS Files).
^r\rMatches a newline (CR Only) (paragraph) (MAC Files).
^n\nMatches a newline (LF Only) (paragraph) (UNIX Files).
^t\tMatches a tab character.
[0-9]\dMatches a digit character.
[~0-9]\DMatches a non-digit character.
[ ^t^b]\sMatches any white space including space, tab, form feed, etc., but not newline.
[~ ^t^b]\SMatches any non-white space character but not newline.
 \vMatches a vertical tab character.
[a-z_]\wMatches any word character including underscore.
[~a-z_]\WMatches any non-word character.
^{A^}^{B^}(A|B)Matches expression A OR B.
^\Overrides the following regular expression character.
^(...^)(...)Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.
^1\1Numerical reference to tagged expressions. Text matched with tagged expressions may be used in Replace commands with this format.
Note: ^ refers to the character '^' NOT Control Key + value.