สอบถามเรื่องjavascriptผมจะเอาตัวเเปรในนั้นมาใช้งานต่อยังไงครับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามเรื่องjavascriptผมจะเอาตัวเเปรในนั้นมาใช้งานต่อยังไงครับ
สอบถามเรื่องjavascriptผมจะเอาตัวเเปรในนั้นมาใช้งานต่อยังไงครับ
ผมอยากได้ค่าตรงเเบงค์เกอร์เอามาเช็คครับ เราจะเอาตัวเเปรของมันมาจากไหนครับ
ตามรูปมันเอาจากหน้าmain_2017.js ไปใส่ในหน้าindexตรง <div id="NextBet"></div>
เราจะรับค่ามันยังไงครับ

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | var ballRed = 'cicle-red' ; var ballBlue = 'cicle-blue' ; var ballGreen = 'cicle-green' ; var setBlue = '<div class="panel-player">เพลเยอร์</div>' ; var setRed = '<div class="panel-bankker">แบงค์เกอร์</div>' ; var ready = '<div class="ready">กรุณากดปุ่ม P เพลเยอร์ หรือ T เสมอ หรือ B แบงค์เกอร์ เพื่อเริ่มการคำนวณค่ะ</div>' ; var refil = '' ; var setResultWIN = '<div class="set-result-re"> ดีใจด้วยนะคะ ไปต่อกันเลยค่ะ</div>' ; var setResultLOSE = '<div class="set-result-re">เสียใจด้วยนะคะ สู้ๆ ค่ะ</div>' ; var setResult1 = '<div class="number-wood">ไม้ 1 </div>' ; var setResult2 = '<div class="number-wood">ไม้ 2 </div>' ; var setResult3 = '<div class="number-wood">ไม้ 3 </div>' ; var setResultCount = '<div class="set-result-count"> </div>' ; var setResultRe = '<div class="set-result-re"> </div>' ; var credit1 = '<div class="set-result-re">กรุณาเติมเครดิต</div>' ; var credit2 = '<div class="set-result-re"> </div>' ; var addBall = function (ball) { $( ".currentBall" ).addClass( "prevBall2" ); $( ".currentBall" ).removeClass( "currentBall" ); $( ".noBall2:first" ).addClass( "currentBall" ); $( ".noBall2:first" ).removeClass( "noBall2" ); $( ".currentBall >.ball2" ).addClass(ball); }; var removeBall = function () { $( ".currentBall >.ball2" ).removeClass( function (index, css) { return (css.match(/(^|s)cicle-S+/g) || []).join( ' ' ); }); $( ".currentBall" ).addClass( "noBall2" ); $( ".prevBall2:last" ).addClass( "currentBall" ); $( ".prevBall2:last" ).addClass( "prevBall2" ); $( ".currentBall:last" ).removeClass( "currentBall" ); $( ".prevBall2:last" ).removeClass( "prevBall2" ); $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); }; var resetBall = function () { $( ".ball-grid2" ).removeClass( "currentBall" ); $( ".ball-grid2" ).removeClass( "prevBall2" ); $( ".ball-grid2" ).addClass( "noBall2" ); $( ".ball-grid2 >.ball2" ).removeClass( function (index, css) { return (css.match(/(^|s)cicle-S+/g) || []).join( ' ' ); }); }; var renderTable = function () { var grid = '<div class="myCol"> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' </div>' ; for (i = 0; i < 12; i++) { $( "#myCalculateTable" ).append(grid); } }; $( function () { renderTable(); loadHistory(); loadCredit(); loadcreditTable(); loadstatisticTable(); $( ".ball-grid2" ).addClass( "noBall2" ); $( "#addBallRed" ).on( "click" , function () { cal2( 'B' ); addBall(ballRed); }); $( "#addBallGreen" ).on( "click" , function () { clickaddballgreen(); addBall(ballGreen); }); $( "#addBallBlue" ).on( "click" , function () { cal2( 'P' ); addBall(ballBlue); }); }); function loadcreditTable() { $( "#creditTable" ).load( "ajax_load_credit.php" ); } function loadHistory() { $( "#statistic" ).load( "ajax_statistic.php" ); } function loadstatisticTable() { $( "#statisticTable" ).load( "ajax_load_statistic.php" ); } function loadchart() { $( "#chart" ).load( "ajax_chart.php" ); } function loadaPlanmoney() { $( "#planmoney" ).load( "ajax_planmoney.php" ); } var cal2 = function (arg) { var url = 'controller/function.php?click=' + arg; $.getJSON(url, function (resp) { console.log( 'cal2.resp >>> ' + JSON.stringify(resp)); if (resp.credit === '0' ) { resetTable(); $( '#Result' ).html(credit1); $( '#NextBet' ).html(credit2); $( '#CountBet' ).html(credit2); } else { if (resp.point === 'B' ) { $( '#NextBet' ).html(setRed); } else if (resp.point === 'P' ) { $( '#NextBet' ).html(setBlue); } else if (resp.point === 'T' ) { $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); } else if (resp.point === '' ) { $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); } if (resp.result === 'WIN' ) { $( '#Result' ).html(setResultWIN); loadHistory(); loadCredit(); loadstatisticTable(); } else if (resp.result === 'LOSE' ) { $( '#Result' ).html(setResultLOSE); loadHistory(); loadstatisticTable(); } else if (resp.result === '' ) { $( '#Result' ).html(setResultRe); $( '#CountBet' ).html(setResultCount); } if (resp.clickWin === '1' ) { $( '#CountBet' ).html(setResult1); } else if (resp.clickWin === '2' ) { $( '#CountBet' ).html(setResult2); } else if (resp.clickWin === '3' ) { $( '#CountBet' ).html(setResult3); } else if (resp.result === '' ) { $( '#CountBet' ).html(setResultCount); } if (resp.point === '' ) { $( '#CountBet' ).html(setResultCount); } } }); }; function clickaddballgreen() { $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); } function undoBall() { removeBall(); $.post( "controller/function.php" , { data: 'undoBall' }, function () { loadCredit() } ); } function loadCredit() { $( "#credit" ).load( "ajax_credit.php" ); } function resetTable() { resetBall(); $.post( "controller/resettableball.php" , { data: 'resetTable' }, function () { window.location.reload(); } ); } function resetHistory() { $.post( "controller/resettablehistorystatatic.php" , { data: 'resetHistory' }, function () { window.location.reload(); } ); } |

ความคิดเห็นที่
2
ไม่แน่ใจว่าหมายถึงอะไร ถ้าเป็นการเอาค่าจาก ตัวแปร setBlue กับ setRed ลองแปลงเป็น jQuery Object แล้วดึงข้อมูล
ด้วยรูปแบบ jQuery ปกติ
1 2 | $(setBlue).text(); $(setRed).text(); |

ความคิดเห็นที่
3
ผมอยากได้ค่าตรงเลข 4 ครับ มันใช่ตรง
รึป่าวคับเเล้วเเปลงยังไง
1 | <div id= "NextBet" ></div> |
รึป่าวคับเเล้วเเปลงยังไง

ความคิดเห็นที่
4
ผมอยากได้ค่าตรง เเบงค์เกอร์ มาเเบบนี้ครับ
1 2 3 4 5 6 | if ( ..ใส่นี่..== 'เเบงค์เกอร์ ' ) { .... } มันต้องใช้ตัวไหน |

ความคิดเห็นที่
5
ค่าจากเลข4 มันเอา มาจากเลข3รึป่าวครับ

ความคิดเห็นที่
6
ดูว่า element หรือ tags ไหนที่คลุมข้อความเราอยู่ แล้วใช้ jQuery จัดการ DOM ดึงค่ามา สมมติว่า
1 | <div id= "xxx" class = "yyy" >เเบงค์เกอร์</div> |
อยากได้ค่าที่อยู่ด้านในหรือก็คือ เเบงค์เกอร์ ก็อาจจะใช้เป็น
1 2 3 4 5 6 7 8 9 | if ($.trim($( "#xxx" ).text())== "เเบงค์เกอร์" ){ } //หรือ if ($.trim($( ".yyy" ).text())== "เเบงค์เกอร์" ){ } |
แต่ถ้ามีตัวอื่นคลุมอีกที เข่น
1 | <div id= "NextBet" ><div id= "xxx" class = "yyy" >เเบงค์เกอร์</div></div> |
ก็อาจจะใช้
1 2 3 | if ($.trim($( "#NextBet div" ).text())== "เเบงค์เกอร์" ){ } |

ความคิดเห็นที่
7
เราจะเช็คค่าออกมาดูยังไงครับ ว่ามันมีค่าอะไรมา
ถ้าเป็นphpก็เเบบนี้
ถ้าเป็นphpก็เเบบนี้
1 2 3 | <?php echo "string" ; ?> |

ความคิดเห็นที่
8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <!DOCTYPE html> <html> <head> <meta charset= "utf-8" > <meta name= "viewport" content= "width=device-width" > <title>JS Bin</title> <style> #place_show_data{ background-color: yellow; color: #000000; width:350px; } </style> </head> <body> <button id= "button1" type= "button" >Run 1</button> <button id= "button2" type= "button" >Run 2</button> <button id= "button3" type= "button" >Run 3</button> <button id= "button4" type= "button" >Reset</button> <br><br> <div id= "place_show_data" > </div> <textarea id= "codesimple" cols= "50" rows= "5" > </textarea> <script> $( function (){ var demoData1 = '<div class="myclass">Data A</div>' ; var demoData2 = '<div class="myclass2">Data B</div>' ; var demoData3 = 'this is test' ; $( "#button1" ).on( 'click' , function (){ $( "#place_show_data" ).html(demoData1); $( "#codesimple" ).html($( "#place_show_data" ).prop( 'outerHTML' )); }); $( "#button2" ).on( 'click' , function (){ $( "#place_show_data" ).html(demoData2); $( "#codesimple" ).html($( "#place_show_data" ).prop( 'outerHTML' )); // if ($.trim($(demoData2).text())== 'Data B' ){ alert($.trim($(demoData2).text())); } }); $( "#button3" ).on( 'click' , function (){ $( "#place_show_data" ).html(demoData3); $( "#codesimple" ).html($( "#place_show_data" ).prop( 'outerHTML' )); }); $( "#button4" ).on( 'click' , function (){ $( "#place_show_data" ).html( '' ); $( "#codesimple" ).html($( "#place_show_data" ).prop( 'outerHTML' )); }); }); </script> </body> </html> |

ความคิดเห็นที่
9
ตัวเเปรอันซ้ายมันจะไปเเสดงหน้าขวา
เเต่ผมไม่รู้ว่าตัว <div id="NextBet"></div> มันมาจากตรงไหนของหน้า main_2017.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | var ballRed = 'cicle-red' ; var ballBlue = 'cicle-blue' ; var ballGreen = 'cicle-green' ; var setBlue = '<div class="panel-player">เพลเยอร์</div>' ; var setRed = '<div class="panel-bankker">แบงค์เกอร์</div>' ; var ready = '<div class="ready">กรุณากดปุ่ม P เพลเยอร์ หรือ T เสมอ หรือ B แบงค์เกอร์ เพื่อเริ่มการคำนวณค่ะ</div>' ; var refil = '' ; var setResultWIN = '<div class="set-result-re"> ดีใจด้วยนะคะ ไปต่อกันเลยค่ะ</div>' ; var setResultLOSE = '<div class="set-result-re">เสียใจด้วยนะคะ สู้ๆ ค่ะ</div>' ; var setResult1 = '<div class="number-wood">ไม้ 1 </div>' ; var setResult2 = '<div class="number-wood">ไม้ 2 </div>' ; var setResult3 = '<div class="number-wood">ไม้ 3 </div>' ; var setResultCount = '<div class="set-result-count"> </div>' ; var setResultRe = '<div class="set-result-re"> </div>' ; var credit1 = '<div class="set-result-re">กรุณาเติมเครดิต</div>' ; var credit2 = '<div class="set-result-re"> </div>' ; var addBall = function (ball) { $( ".currentBall" ).addClass( "prevBall2" ); $( ".currentBall" ).removeClass( "currentBall" ); $( ".noBall2:first" ).addClass( "currentBall" ); $( ".noBall2:first" ).removeClass( "noBall2" ); $( ".currentBall >.ball2" ).addClass(ball); }; var removeBall = function () { $( ".currentBall >.ball2" ).removeClass( function (index, css) { return (css.match(/(^|s)cicle-S+/g) || []).join( ' ' ); }); $( ".currentBall" ).addClass( "noBall2" ); $( ".prevBall2:last" ).addClass( "currentBall" ); $( ".prevBall2:last" ).addClass( "prevBall2" ); $( ".currentBall:last" ).removeClass( "currentBall" ); $( ".prevBall2:last" ).removeClass( "prevBall2" ); $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); }; var resetBall = function () { $( ".ball-grid2" ).removeClass( "currentBall" ); $( ".ball-grid2" ).removeClass( "prevBall2" ); $( ".ball-grid2" ).addClass( "noBall2" ); $( ".ball-grid2 >.ball2" ).removeClass( function (index, css) { return (css.match(/(^|s)cicle-S+/g) || []).join( ' ' ); }); }; var renderTable = function () { var grid = '<div class="myCol"> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' <div class="ball-grid2"><div class="ball2"></div></div> ' ; grid += ' </div>' ; for (i = 0; i < 12; i++) { $( "#myCalculateTable" ).append(grid); } }; $( function () { renderTable(); loadHistory(); loadCredit(); loadcreditTable(); loadstatisticTable(); $( ".ball-grid2" ).addClass( "noBall2" ); $( "#addBallRed" ).on( "click" , function () { cal2( 'B' ); addBall(ballRed); }); $( "#addBallGreen" ).on( "click" , function () { clickaddballgreen(); addBall(ballGreen); }); $( "#addBallBlue" ).on( "click" , function () { cal2( 'P' ); addBall(ballBlue); }); }); function loadcreditTable() { $( "#creditTable" ).load( "ajax_load_credit.php" ); } function loadHistory() { $( "#statistic" ).load( "ajax_statistic.php" ); } function loadstatisticTable() { $( "#statisticTable" ).load( "ajax_load_statistic.php" ); } function loadchart() { $( "#chart" ).load( "ajax_chart.php" ); } function loadaPlanmoney() { $( "#planmoney" ).load( "ajax_planmoney.php" ); } var cal2 = function (arg) { var url = 'controller/function.php?click=' + arg; $.getJSON(url, function (resp) { console.log( 'cal2.resp >>> ' + JSON.stringify(resp)); if (resp.credit === '0' ) { resetTable(); $( '#Result' ).html(credit1); $( '#NextBet' ).html(credit2); $( '#CountBet' ).html(credit2); } else { if (resp.point === 'B' ) { $( '#NextBet' ).html(setRed); } else if (resp.point === 'P' ) { $( '#NextBet' ).html(setBlue); } else if (resp.point === 'T' ) { $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); } else if (resp.point === '' ) { $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); } if (resp.result === 'WIN' ) { $( '#Result' ).html(setResultWIN); loadHistory(); loadCredit(); loadstatisticTable(); } else if (resp.result === 'LOSE' ) { $( '#Result' ).html(setResultLOSE); loadHistory(); loadstatisticTable(); } else if (resp.result === '' ) { $( '#Result' ).html(setResultRe); $( '#CountBet' ).html(setResultCount); } if (resp.clickWin === '1' ) { $( '#CountBet' ).html(setResult1); } else if (resp.clickWin === '2' ) { $( '#CountBet' ).html(setResult2); } else if (resp.clickWin === '3' ) { $( '#CountBet' ).html(setResult3); } else if (resp.result === '' ) { $( '#CountBet' ).html(setResultCount); } if (resp.point === '' ) { $( '#CountBet' ).html(setResultCount); } } }); }; function clickaddballgreen() { $( '#CountBet' ).html(setResultCount); $( '#Result' ).html(setResultRe); $( '#NextBet' ).html(ready); } function undoBall() { removeBall(); $.post( "controller/function.php" , { data: 'undoBall' }, function () { loadCredit() } ); } function loadCredit() { $( "#credit" ).load( "ajax_credit.php" ); } function resetTable() { resetBall(); $.post( "controller/resettableball.php" , { data: 'resetTable' }, function () { window.location.reload(); } ); } function resetHistory() { $.post( "controller/resettablehistorystatatic.php" , { data: 'resetHistory' }, function () { window.location.reload(); } ); } |

ความคิดเห็นที่
10
งั้นบรรทัด 107 109 มันเอาไปไว้ในนี้หรอครับ
คือผมจะทำเงื่อนไขเเบบนี้
เขียนเเบบนี้หรอครับ
โทษทีครับผมไม่เคยเขียน js มาก่อน
1 | <div id= "NextBet" ></div> |
คือผมจะทำเงื่อนไขเเบบนี้
1 2 3 4 5 6 | if (NextBet== 'เพลเยอร์' ) { # code... } if (NextBet== 'แบงค์เกอร์' ) { # code... } |
โทษทีครับผมไม่เคยเขียน js มาก่อน

ขอบคุณทุกการสนับสนุน
![]()