วันอังคารที่ 15 มกราคม พ.ศ. 2556

ข้อสอบ กพ.

พัฒนา/ปรับแต่ง maxsite การซ่อนหรือแสดงส่วนต่างๆ ของเว็บด้วย javascript

วันนี้มานำเสนอ การประยุกต์ใช้ code ที่มีอยู่ใน maxsite เช่น การซ่อน/แสดง emotion
เราก็เอามาปรับสำหรับ ซ่อนหรือแสดง ส่วนของเนื้อหาเราดีกว่าครับ ดูตัวอย่างง่ายๆ ในเวบบอร์ดของผม สำหรับส่วนการแนบไฟล์ในเวบบอร์ด ที่สามารถซ่อนหรือแสดงส่วนนี้ได้
(by narongrit.net)
1. ยกตัวอย่างเปิดไฟล์ modules/webboard/post.php แล้วเพิ่มโค้ดนี้ในส่วน javascript ที่มีอยู่เดิม

1function showtest() {
2    test1.style.display = 'none';
3    test2.style.display = '';
4}
5function closetest() {
6    test1.style.display = '';
7    test2.style.display = 'none';
8}
 
1function showtest() {
2    test1.style.display = 'none';
3    test2.style.display = '';
4}
5function closetest() {
6    test1.style.display = '';
7    test2.style.display = 'none';
8}
ถ้ารวมกับโค้ดเดิมก็จะเป็นแบบนี้ครับ (by narongrit.net)
 
<script type="text/javascript">
02function showemotion() {
03    emotion1.style.display = 'none';
04    emotion2.style.display = '';
05}
06function closeemotion() {
07    emotion1.style.display = '';
08    emotion2.style.display = 'none';
09}
10  
11function showtest() {
12    test1.style.display = 'none';
13    test2.style.display = '';
14}
15function closetest() {
16    test1.style.display = '';
17    test2.style.display = 'none';
18}
19  
20function emoticon(theSmilie) {
21  
22    document.form2.detail.value += ' ' + theSmilie + ' ';
23    document.form2.detail.focus();
24}
25</script>
01<script type="text/javascript">
02function showemotion() {
03    emotion1.style.display = 'none';
04    emotion2.style.display = '';
05}
06function closeemotion() {
07    emotion1.style.display = '';
08    emotion2.style.display = 'none';
09}
10  
11function showtest() {
12    test1.style.display = 'none';
13    test2.style.display = '';
14}
15function closetest() {
16    test1.style.display = '';
17    test2.style.display = 'none';
18}
19  
20function emoticon(theSmilie) {
21  
22    document.form2.detail.value += ' ' + theSmilie + ' ';
23    document.form2.detail.focus();
24}
25</script>
จากนั้น หากต้องการซ่อนหรือแสดง ก็เอาโค้ดตัวอย่างนี้ไปปรับใช้ดูครับ (by narongrit.net)
 
<div id="test1">
02           <table align="left" width="100%">
03    <TR>
04    <TD><a href="javascript:showtest();">แสดงเนื้อหา</a></TD></TR>
05    </table> </div>
06                <div id="test2" style="display: none;">
07      <table align="left" width="100%">
08    <TR>
09    <TD align="left" width="100"><font color="red">ส่วนของเนื้อหา</font>
10</TD>
11    <TD><a href="javascript:closetest();">ซ่อนเนื้อหา </a>
12</TD>
13  </TR>
14    </table>
15         </div>
01<div id="test1">
02           <table align="left" width="100%">
03    <TR>
04    <TD><a href="javascript:showtest();">แสดงเนื้อหา</a></TD></TR>
05    </table> </div>
06                <div id="test2" style="display: none;">
07      <table align="left" width="100%">
08    <TR>
09    <TD align="left" width="100"><font color="red">ส่วนของเนื้อหา</font>
10</TD>
11    <TD><a href="javascript:closetest();">ซ่อนเนื้อหา </a>
12</TD>
13  </TR>
14    </table>
15         </div>
ดูตัวอย่างผลที่ได้จากลิงค์นี้ครับhttp://www.narongrit.net/maxnrr/?name=webboard&file=post
หากมีข้อสงสัย สอบถามได้ที่เวบบอร์ดนะครับ

หรือจะดาวน์โหลดไฟล์ด้านล่างนี้ไปดูเป็นตัวอย่างก็ได้ครับ

เขียนและเรียบเรียง
webmaster
www.narongrit.net

พัฒนา/ปรับแต่ง maxsite วิธีการซ่อนหรือแสดงบางส่วนในหน้าเว็บ สำหรับสมาชิก

สำหรับใครที่ใช้ระบบสมาชิกที่ผมแจกนั้น จะใช้ตัวแปรเซสชั่นชื่อ login_true เป็นตัวกำหนดว่าสมาชิกคนนั้น login หรือยัง ก็ให้ใช้โค้ดนี้ในการแสดงส่วนที่ต้องการให้เฉพาะสมาชิกเท่านั้นถึงจะเห็นนะครับ


01 if (!$_SESSION['login_true']){
02
03 ส่วนของโค้ดที่ต้องการแสดงเฉพาะสมาชิก
04
05 } else { echo "<font color="red">ส่วนนี้สำหรับสมาชิกเท่านั้น</font>"; }

เช่น ถ้าเราต้องการแสดงปุ่ม upload รูปให้เฉพาะสมาชิกเราก็อาจแปลงโค้ดได้ดังนี้
01<?
02//โค้ดซ่อนแสดงส่วนต่างๆ เฉพาะสมาชิก เท่านั้น โดย www.narongrit.net
03if (!$_SESSION['login_true']){
04  
05?>
06<input type="file" name="FILE" style="width:250" class="inputform"> Limit <?=(_WEBBOARD_LIMIT_UPLOAD/1024);?> kB
07<?
08} else { echo "<font color='red'>ส่วนนี้สำหรับสมาชิกเท่านั้น</font>"; }
09// end code www.narongrit.net
10?>
 
โค้ดลักษณะนี้ ผมใช้ซ่อน capcha สำหรับสมาชิก ที่ login และซ่อนปุ่ม upload ไฟล์นั่นเอง

เขียนและเรียบเรียงโดย

webmaster
www.narongrit.net