(1)javascript
焦點
document.getElementById('field1').focus();
反白
document.getElementById('field1').select();
(2)jQuery
//當class為link_column且此欄位focus時,把此欄位反白
$(document).ready(function(){
$(".link_column").focus(function() {
$(this).select();
});
});
//欄位內容反白
function click_data(txt_id){
$(txt_id).focus(); //焦點
}
<input class="link_column" type="text" name="txt1" id='txt1' onclick="click_data('txt1');>
2008年10月22日 星期三
防止Sql injection和XSS injection
傳入string,傳回string
function checksql($str) {
$str = @htmlspecialchars($str);
//過濾單引號成為全形單引號
$str = str_replace("'","’",$str);
//過濾雙引號成為全形雙引號
$str = str_replace('"',"”",$str);
return $str;
}
function checksql($str) {
$str = @htmlspecialchars($str);
//過濾單引號成為全形單引號
$str = str_replace("'","’",$str);
//過濾雙引號成為全形雙引號
$str = str_replace('"',"”",$str);
return $str;
}
字串轉成浮點數或整數
將字串轉成浮點數並傳回值:
parseFloat(字串)
將字串轉成基底的整數並傳回值:
parseInt(字串,基底)
基底是指幾進位:如十進位、十六進位…
parseInt('010',10)
parseFloat(字串)
將字串轉成基底的整數並傳回值:
parseInt(字串,基底)
基底是指幾進位:如十進位、十六進位…
parseInt('010',10)
Mouse Over 的效果
Script:
$(document).ready(function(){
//當id為tdata,tr的id開頭不等於line,當滑鼠移到時加入class,離開時移除class
$("#tdata tr:not([id^='line'])").hover(
function () {$(this).addClass("class_01");},
function () {$(this).removeClass("class_01");}
);
});
Html:
<table border="1" id="tdata">
<tr id="line" class="class_02">
<td>欄位</td>
</tr>
<tr>
<td>資料</td>
</tr>
</table>
$(document).ready(function(){
//當id為tdata,tr的id開頭不等於line,當滑鼠移到時加入class,離開時移除class
$("#tdata tr:not([id^='line'])").hover(
function () {$(this).addClass("class_01");},
function () {$(this).removeClass("class_01");}
);
});
Html:
<table border="1" id="tdata">
<tr id="line" class="class_02">
<td>欄位</td>
</tr>
<tr>
<td>資料</td>
</tr>
</table>
table 基偶列不同顏色
Script:
$(document).ready(function(){
//當id為tdata,tr的id開頭不等於line的加入class
$("#tdata tr:not([id^='line']):even").addClass('class_03');
$("#tdata tr:not([id^='line']):odd").addClass('class_04');
//或id的開頭為tdata,tr的id開頭不等於line的加入class
$("[id^='tdata'] tr:not([id^='line']):even").addClass('td_blue_03');
$("[id^='tdata'] tr:not([id^='line']):odd").addClass('td_green_04');
//或
$("#tdata tr:even").addClass('table_even');
$("#tdata tr:odd").addClass('table_odd');
});
Html:
<table border="1" id="tdata">
<tr id="line" class="class_02">
<td>欄位</td>
</tr>
<tr>
<td>資料</td>
</tr>
</table>
$(document).ready(function(){
//當id為tdata,tr的id開頭不等於line的加入class
$("#tdata tr:not([id^='line']):even").addClass('class_03');
$("#tdata tr:not([id^='line']):odd").addClass('class_04');
//或id的開頭為tdata,tr的id開頭不等於line的加入class
$("[id^='tdata'] tr:not([id^='line']):even").addClass('td_blue_03');
$("[id^='tdata'] tr:not([id^='line']):odd").addClass('td_green_04');
//或
$("#tdata tr:even").addClass('table_even');
$("#tdata tr:odd").addClass('table_odd');
});
Html:
<table border="1" id="tdata">
<tr id="line" class="class_02">
<td>欄位</td>
</tr>
<tr>
<td>資料</td>
</tr>
</table>
2008年10月20日 星期一
只能填數字和小數點
javascript:
function check_keyPress(e){
if ($.browser.msie){ //ie
keycode = event.keyCode;
}else{ //其它
keycode = e.which;
}
if ((keycode > 57 || keycode < 48) && (keycode != 46) && (keycode != 13)) {
return false;
}
}
html:
<input type="text" name="text1" value="" size="5" onkeypress="return check_keyPress(event)">
function check_keyPress(e){
if ($.browser.msie){ //ie
keycode = event.keyCode;
}else{ //其它
keycode = e.which;
}
if ((keycode > 57 || keycode < 48) && (keycode != 46) && (keycode != 13)) {
return false;
}
}
html:
<input type="text" name="text1" value="" size="5" onkeypress="return check_keyPress(event)">
判斷按下的是鍵盤的哪個鍵
javascript:
function check_keyPress(e){
(1)
if ($.browser.msie){ //ie
keycode = event.keyCode;
}else{ //其它
keycode = e.which;
}
alert(keycode);
PS.發現無法判斷上、下、左、右鍵
(2)
var keycode = (e.which) ? e.which : event.keyCode
}
html:
<input type="text" name="text1" value="" size="5" onkeypress="check_keyPress(event)">
function check_keyPress(e){
(1)
if ($.browser.msie){ //ie
keycode = event.keyCode;
}else{ //其它
keycode = e.which;
}
alert(keycode);
PS.發現無法判斷上、下、左、右鍵
(2)
var keycode = (e.which) ? e.which : event.keyCode
}
html:
<input type="text" name="text1" value="" size="5" onkeypress="check_keyPress(event)">
欄位只能填數字-for IE
<input type="text" name="numberin" size="5" value="" id="numberin" onKeyPress="with(window.event)return(keyCode>47&&keyCode<58)">
2008年10月2日 星期四
訂閱:
文章 (Atom)