跳到主要內容

javascript字串轉換

當我們在執行網頁間的傳送資料時,字串間常會有出現『/#+!...』的特殊字眼。
而接收方的網頁上常常會以空白的方式呈現,或是直接消失。造成錯誤的資料傳遞。
為避免此情況發生,我們可以使用 javascript encodeURIComponent() 函式先將傳送方的資料做一次utf-8編碼。
使用方法:
傳送方網頁 send.html
<html>
  < head>
   < title> 傳方送方 < /title>
   < script type="text/javascript">
    function query_send() {
     tourl = 'doquery.php';
     send_variable = "supply_id=" + document.getElementById('supply_id').value;
     send_variable += "&memo_key=" + encodeURIComponent(document.getElementById('memo_key').value);
     post_ajax(tourl, show_list, send_variable);
    }
     function show_list() {
       if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           document.getElementById('list_area').innerHTML = http_request.responseText;
         }
       }
    }
  < /script>
</HEAD>
<BODY>
   查詢條件:
           廠商:  < INPUT TYPE='text' id='supply_id' style='width:50px'>
           備註:  < INPUT TYPE='text' id='memo_key' style='width:120px'>
            < A href='javascript:void(0)' onclick='query_send()' > 查詢 < /A>
     < DIV id='list_area' >   < /DIV>
</BODY>
</HTML>

--------------------------------------------------------------------------------------
接收方網頁 doquery.php
<? php
    $supply_id = $_REQUEST['supply_id'];
    $memo_key  = stripSlashes(htmlentities($_REQUEST['memo_key'])); // 因為encodeURIComponent不處理單引號,所以,於PHP程式中再處理單引號的轉換。
    echo "廠商內容:".$supply_id."
備註內容:".$memo_key;
?>

留言

這個網誌中的熱門文章

安裝webmin

Webmin是一套透過網頁的界面來維護linux主機各項伺服器的程式,非常的好用方便。 其安裝方式如下: 1. 在yum.repos.d資料夾下新增一個設定檔。     vi /etc/yum.repos.d/webmin.repo     [Webmin]       name=Webmin Distribution Neutral       baseurl=http://download.webmin.com/download/yum       enabled=1 2. 匯入GPGkey     rpm --import http://www.webmin.com/jcameron-key.asc     如果系統顯示匯入失敗。可改下列做法     wget http://www.webmin.com/jcameron-key.asc     rpm --import jcameron-key.asc 3. 執行安裝     yum install -y webmin 4. 設定使用者及密碼     /usr/libexec/webmin/changepass.pl /etc/webmin 帳號 密碼

CSS 文字效果

text-decoration 於 CSS 中定義為設定 文字效果 屬性有: 1. none ─ 預設值 2. overline ─ 文字標上線 3. underline ─ 文字標底線 4. line-throughx ─ 文字標刪除線 5. blink ─ 文字閃爍

Colorbox 使用筆記

Colorbox 詳細使用說明請參考 a jQuery lightbox 情境一: 當開發RWD網頁時,我想將 lightbox 的寬度依顯示螢幕的寬度來決定。 想讓 lightbox 的內容不會太擁擠或太空洞。 <script> var deviceWidth = 0; $(function() { deviceWidth = $(window).width(); $(window).resize(function(){ deviceWidth = $(window).width(); }); }); function showMessage() { var colorboxWidth = "100%"; if (deviceWidth > 767) { colorboxWidth = "70%"; } $.colorbox({innerWidth: colorbox}); } </script> 情境二: 為了讓使用者確實閱讀完 lightbox 內的訊息,想將關閉 lightbox 的熱鍵移除。 <script> function showMessage() { $.colorbox({ escKey: false,  // 按下esc鍵關閉 Colorbox 視窗 arrowKey: false,  // 按下方向鍵關閉 Colorbox 視窗 overlayClose: false  // 在背景遮罩點一下滑鼠左鍵,關閉 Colorbox 視窗 }); } </script> 情境三: 當 Lightbox 內的訊息太長,或需要互動性質的內容,開啓 iframe 功能,互動換頁才不會讓整個網頁換掉。 <script> function showMessage() { $.colorbox({ escKey: false, arrowKey: false, o...