วันอังคารที่ 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

ไม่มีความคิดเห็น:

แสดงความคิดเห็น