ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingช่วยด้วยครับ พี่ๆเก่งๆ javascript
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ช่วยด้วยครับ พี่ๆเก่งๆ javascript  (อ่าน 675 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
JumDaiDee
สมุนแก๊งเสียว
*

พลังน้ำใจ: 18
ออฟไลน์ ออฟไลน์

กระทู้: 566



ดูรายละเอียด
« เมื่อ: 30 สิงหาคม 2014, 10:44:49 »

จาก code นี้  ต้องแก้โค้ดอย่างไรครับ
เมื่อคลิก btn แล้ว อยากให้ cursor default อยู่ตรงกลาง ระหว่างแท็กครับ
ตัวอย่าง ["b] แสดง sursor โดยไม่ต้องคลิกเองครับ [/b]

อ้างถึง
<html>
<head>
<script type="text/javascript">
function addtag(tag) {
   var txt = document.getElementById('mta');
   if(document.selection) {
      txt.focus();
      sel = document.selection.createRange();
      sel.text = '['   tag   ']'   sel.text   '[/'   tag   ']';
   } else if(txt.selectionStart || txt.selectionStart == '0') {   
      txt.value = (txt.value).substring(0, txt.selectionStart)   "[" tag "]"   (txt.value).substring(txt.selectionStart, txt.selectionEnd)   "[/" tag "]"   (txt.value).substring(txt.selectionEnd, txt.textLength);
   } else {
      txt.value = '['   tag   '][/'   tag   ']';
   }
   return;
}
function addurltag() {
   var txt = document.getElementById('mta');
   var link = prompt("Type the address:", "http://");
   if(link.length == 0 || link == "http://") {
      return;
   } else {
      var link = "="   link;
      var text;
      var sel2 = "";
      if(document.selection) {
         txt.focus();
         sel = document.selection.createRange();
         sel2 = sel.text;
      } else if(txt.selectionStart || txt.selectionStart == '0') {
         sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
      }
      if(sel2.length > 0) {
         text = sel2;
      } else {
         text = prompt("Enter the link text:", "");
      }
   }
   if(document.selection) {
      txt.focus();
      sel = document.selection.createRange();
      sel.text = "[url"   link   "]"   text   "[/url]";
   } else {
      txt.value = (txt.value).substring(0, txt.selectionStart)   "[url"   link   "]"   text   "[/url]"   (txt.value).substring(txt.selectionEnd, txt.textLength);
   }
   return;
}
</script>
<style type="text/css">
.bbButton {
   height: 30px;
   font-family: serif;
   font-size: 16pt;
}
</style>
</head>
<body>
<input type="button" value="B" onclick="addtag('b')" class="bbButton" style="width:30px; font-weight:bold;" />
<input type="button" value="I" onclick="addtag('i')" class="bbButton" style="width:30px; font-style:italic;" />
<input type="button" value="U" onclick="addtag('u')" class="bbButton" style="width:30px; text-decoration:underline;" />
<input type="button" value="Link" onclick="addurltag()" class="bbButton" />
<input type="button" value="List" onclick="addtag('list')" class="bbButton" />
<input type="button" value="Code" onclick="addtag('code')" class="bbButton" /><br />
<br />
<textarea id="mta" name="mta" cols="40" rows="7"></textarea>
</body>
</html>


 wanwan017 wanwan017
« แก้ไขครั้งสุดท้าย: 30 สิงหาคม 2014, 10:46:20 โดย JumDaiDee » บันทึกการเข้า

สินค้าออนไลน์ https://www.shoppook.com/product | โปรแกรมออนไลน์ : https://appnon.com
scanfire
ก๊วนเสียว
*

พลังน้ำใจ: 23
ออฟไลน์ ออฟไลน์

กระทู้: 245



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 30 สิงหาคม 2014, 12:05:27 »

ลองไล่ใหม่อีกครับ ผมเอาไปลองเทส alert ค่าไม่ออกเลย

ลองเปลี่ยนเป็น event click เพื่อdebug ดูก่อนนะ

http://stackoverflow.com/quest...sor-is-using-javascript-jquery

ขอโทษนะช่วยได้แค่นี้งานเยอะ
บันทึกการเข้า

ทำเว็บไซต์ Magento, รับทำเว็บไซน์ขายของ ,รับตัดเว็บไซต์ responsive  ,รับทำแอพมือถือ ,สอนเขียนโปรแกรม, บริษัทรับทำเว็บไซต์
โทร : 0970011614, 063-187-5099
email : [email protected]
JumDaiDee
สมุนแก๊งเสียว
*

พลังน้ำใจ: 18
ออฟไลน์ ออฟไลน์

กระทู้: 566



ดูรายละเอียด
« ตอบ #2 เมื่อ: 30 สิงหาคม 2014, 12:57:46 »

ผมหาเจอ แล้วครับ

http://aktuell.de.selfhtml.org/artikel/javascript/bbcode/

 wanwan020 wanwan020
บันทึกการเข้า

สินค้าออนไลน์ https://www.shoppook.com/product | โปรแกรมออนไลน์ : https://appnon.com
scanfire
ก๊วนเสียว
*

พลังน้ำใจ: 23
ออฟไลน์ ออฟไลน์

กระทู้: 245



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 30 สิงหาคม 2014, 13:52:17 »

ว่าแต่ทำไมไม่ใช้ editor ที่เค้าพัฒนาแล้วอะครับ สงสัย

ไปปิดงานมาพอดี เห็นได้แล้วยินดีด้วยนะครับ
บันทึกการเข้า

ทำเว็บไซต์ Magento, รับทำเว็บไซน์ขายของ ,รับตัดเว็บไซต์ responsive  ,รับทำแอพมือถือ ,สอนเขียนโปรแกรม, บริษัทรับทำเว็บไซต์
โทร : 0970011614, 063-187-5099
email : [email protected]
JumDaiDee
สมุนแก๊งเสียว
*

พลังน้ำใจ: 18
ออฟไลน์ ออฟไลน์

กระทู้: 566



ดูรายละเอียด
« ตอบ #4 เมื่อ: 02 กันยายน 2014, 08:10:36 »

ว่าแต่ทำไมไม่ใช้ editor ที่เค้าพัฒนาแล้วอะครับ สงสัย

ไปปิดงานมาพอดี เห็นได้แล้วยินดีด้วยนะครับ

อ๋อ พอดี ผมจะเพิ่ม ปุ๋มพิเศษ ส่วนตัว ถ้าเข้าไปแก้ editor เค้าคงจะยากกว่า
ก็เลย ลองหาดูเล่นๆ ครับ จนเจอจนได้ ขอบคุณครับ
บันทึกการเข้า

สินค้าออนไลน์ https://www.shoppook.com/product | โปรแกรมออนไลน์ : https://appnon.com
หน้า: [1]   ขึ้นบน
พิมพ์