|
 |
|
ใครพอจะมีตัวอย่างการหช่วงตัวเลข หรือเปล่าครับ อยากให้ textbox รับค่าตัวเลขตั้งแต่ 1 ถึง จำนวนที่เรากำหนด พอจะมีจะสคริปไหม |
|
 |
|
|
 |
 |
|
ใช้ javascript ตรวจสอบสิครับ
จาวาสคริป เขียนไม่เป็น แต่ถ้า php ก็
ใช้ if สิ
ตอบตรงประเด็นป้ะ
|
 |
 |
 |
 |
Date :
2009-06-09 13:50:46 |
By :
suredestiny |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ แต่อยากได้ อยากทำเป็น alret อะครับ เมื่อผู้ใช้ งานป้อนตัวเลขเกินจำนวนที่เรากำหนด ก็จะ alret ขึ้นแจ้งให้ทราบ อะครับ แต่ผมเขียน java ไม่เป็นด้วยสิ แต่ให้แกะโค้ดก้อพอได้ อิอิ
|
 |
 |
 |
 |
Date :
2009-06-09 14:55:27 |
By :
drakvender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แกะได้ก็ต้องเขียนพอได้บ้างแล้วล่ะครับ เพราะมันก็เขียนเหมือน php น่ะแหละ 
ว่าแต่ชาตินี้จะแกะอย่างเดียว จะไม่หัดเขียนเลยหรอครับ
|
 |
 |
 |
 |
Date :
2009-06-09 15:18:06 |
By :
nut_t02 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ nut_t02 ไม่ช่วยก้อขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-06-09 17:34:19 |
By :
drakvender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ใช้ if check ว่า ตัวเลขที่รับค่ามา มัน มากกว่า หรือน้อยกว่าค่าที่กำหนด แล้วก็ alert ขึ้นมาครับ
|
 |
 |
 |
 |
Date :
2009-06-09 17:58:31 |
By :
ail2geal2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้ารับค่า ตั้งแต่ 1-10 ก็ if(num< 1|| num>10){ก็ให้มัน alert } ประมาณนี้
|
 |
 |
 |
 |
Date :
2009-06-09 17:59:46 |
By :
ail2geal2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2009-06-09 18:01:30 |
By :
drakvender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนตัวอย่างให้ดูครับ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="th" xml:lang="th">
<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620" />
<title>javascript only digit textbox</title>
<script type="text/javascript">
//<![CDATA[
function replaceDigit(el){
el.value=el.value.replace(/\D/,'');
}
function acceptOnlyDigit(event,el){
var e=window.event?window.event:event;
var keyCode=e.keyCode?e.keyCode:e.which?e.which:e.charCode;
//0-9 (numpad,keyboard)
if ((keyCode>=97 && keyCode<=105)||(keyCode>=48 && keyCode<=57)){
return true;
}
//backspace,delete,left,right,home,end
if ('8,46,37,39,36,35,'.indexOf(keyCode+',')!=-1){
return true;
}
return false;
}
//]]>
</script>
</head>
<body>
<form method="post" action="?" id="box">
<br/>replace digit: <input type="text" name="onlydigit" value="" onkeyup="replaceDigit(this)" />
<br/>accept only digit: <input type="text" name="onlydigit2" value="" onkeydown="return acceptOnlyDigit(event,this)" />
</form>
</body>
</html>
javascript-accept-only-digit-textbox
|
 |
 |
 |
 |
Date :
2009-06-09 18:49:04 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขบรรทัดนี้ครับ
if ('8,46,37,39,36,35,'.indexOf(keyCode+',')!=-1){
return true;
}
เป็น
if (',8,46,37,39,36,35,'.indexOf(','+keyCode+',')!=-1){
return true;
}
|
 |
 |
 |
 |
Date :
2009-06-09 18:51:26 |
By :
num |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ ท่า num มากครับ
|
 |
 |
 |
 |
Date :
2009-06-10 10:31:52 |
By :
drakvender |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|