jQuery

ajax

// 範例
$.ajax({
  url: "url",
  async: false,
  data:{
    pid : 123,
    action: "456"
  },
  dataType: 'json',
  success: function(data) {
    console.log(data)
  },
  error: function(error){
    console.log(error)
  }
});

常見參數: type = 請求方式,預設get async = true or false,預設為true,所有請求均為非同步請求。改為false則同步請求將鎖住瀏覽器,使用者其它操作必須等待請求完成才可以執行。 contentType = 傳送資訊至伺服器時內容編碼型別。預設:application/x-www-form-urlencoded data = 發送到伺服器的資料。將自動轉換為請求字串格式。 dataType = 預期伺服器返回的資料型別。

https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/272853/arrow-up-right

https://blog.reh.tw/archives/662arrow-up-right

介紹

https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/272853/arrow-up-right

success and error

http://www.pureexample.com/tw/jquery/ajax-success-and-error.htmlarrow-up-right

另一種post寫法 (尚未與ajax比較)

https://stackoverflow.com/questions/18697034/how-to-pass-parameters-in-ajax-post/35590754arrow-up-right

傳送json資料 (400)

https://stackoverflow.com/questions/21738663/getting-json-in-flask-from-jquery-ajaxarrow-up-right

用enter送出

https://www.formget.com/submit-your-form-on-pressing-enter-key-using-jquery/arrow-up-right

https://stackoverflow.com/questions/699065/submitting-a-form-on-enter-with-jqueryarrow-up-right

json物件處理

使用ajax post時可用JSON.stringify()轉換型態後再傳送

使用ajax get接收回傳結果時可用JSON.parse()轉換型態

https://www.w3schools.com/js/js_json_parse.asparrow-up-right

遍歷方法

https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/258763/arrow-up-right

https://t.codebug.vip/questions-342113.htmarrow-up-right

替換特殊字元(換行、雙引號)

https://stackoverflow.com/questions/4253367/how-to-escape-a-json-string-containing-newline-characters-using-javascriptarrow-up-right

日期選擇器

http://www.daterangepicker.com/arrow-up-right

https://www.wfublog.com/2017/08/jquery-date-range-picker-bootstrap.htmlarrow-up-right

https://dotblogs.com.tw/shadow/2017/11/28/001719arrow-up-right

取得check box值

http://blog.twbryce.com/jquery-get-checkbox-value/arrow-up-right

常用語法

checkbox 全選

http://dev.sopili.net/2013/03/bootstrap-css.htmlarrow-up-right

cdn介紹

https://blog.csdn.net/zyz1985/article/details/6828790arrow-up-right

https://hkitblog.com/%E4%B8%8D%E5%8F%AF%E4%B8%8D%E7%9F%A5%E7%9A%84-cdn-%E7%A8%AE%E9%A1%9E%EF%BC%81%E7%94%9A%E9%BA%BC%E6%98%AF%E5%8B%95%E6%85%8B%E3%80%81%E9%9D%9C%E6%85%8B-cdn%EF%BC%9Fevent-driven-%E7%AE%97%E6%98%AF/arrow-up-right

string 格式化

https://www.cnblogs.com/taoweiji/p/3260883.htmlarrow-up-right

radio

https://blog.csdn.net/enjoyo/article/details/1700228arrow-up-right

https://blog.xuite.net/vv650812/twblog/229550316-jQuery+%E4%B9%8B+checkbox+%E5%8F%8A+radio+%E5%8F%96%E5%80%BC%E5%8F%8A%E8%A8%AD%E5%AE%9A%E5%80%BC%E7%9A%84%E6%AD%A3%E7%A2%BA%E6%96%B9%E6%B3%95arrow-up-right

select

取值

http://n.sfs.tw/content/index/10047arrow-up-right

onload vs ready

ready,表示文件結構已經載入完成(不包含圖片等非文字媒體檔案)

onload,指示頁 麵包含圖片等檔案在內的所有元素都載入完成。

ready 在onload 前載入!!!

https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/290536/arrow-up-right

function

https://melomelo1988.pixnet.net/blog/post/263934328arrow-up-right

https://matthung0807.blogspot.com/2017/11/jquery-document-ready.htmlarrow-up-right

button事件觸發

https://www.w3school.com.cn/jquery/jquery_ref_events.asparrow-up-right

https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/232048/arrow-up-right

window.onload vs $(document).ready

ready:DOM下載完成就觸發function,啟動時機較早,前一次跟後一次所設定的函式都會被執行。

onload:除了DOM,連同其中的圖片影音的內容都下載完才會觸發function,啟動時機較晚,後一次所設定的函式會複寫上一次的。

https://ithelp.ithome.com.tw/articles/10092601arrow-up-right

https://matthung0807.blogspot.com/2017/11/jquery-document-ready.htmlarrow-up-right

複寫

onload只會執行第二個,第一個會被忽略

https://blog.xuite.net/coke750101/networkprogramming/31375424-%5BjQuery%5D%24%28document%29.ready%E5%92%8Conload%E4%BA%8B%E4%BB%B6%E7%9A%84%E5%B7%AE%E7%95%B0arrow-up-right

setInterval

https://neohsuxoops.blogspot.com/2018/04/ajaxfunction.htmlarrow-up-right

https://kuro.tw/posts/2019/02/23/%E8%AB%87%E8%AB%87-JavaScript-%E7%9A%84-setTimeout-%E8%88%87-setInterval/arrow-up-right

https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/276882/arrow-up-right

.html() .text() .val()

http://androchen.blogspot.com/2013/04/jquery-html-text-val.htmlarrow-up-right

jQuery equivalent to “getElementsByName”

https://stackoverflow.com/questions/9711917/jquery-equivalent-to-getelementsbynamearrow-up-right

更新CSS

全域變數 vs 區域變數

1.變數宣告在function外面,不管有沒有加上var都是全域變數

2.變數宣告在function之內,沒有加上var就會成為全域變數

https://engmeter.blogspot.com/2015/03/jqueryjquery.htmlarrow-up-right

settimeout

confirm

https://www.w3schools.com/jsref/met_win_confirm.asparrow-up-right

textarea 的取值和給值

http://n.sfs.tw/content/index/10044arrow-up-right

https://www.w3schools.com/tags/tag_textarea.asparrow-up-right

onchange event for input type=“number”

https://stackoverflow.com/questions/9609731/onchange-event-for-input-type-numberarrow-up-right

四捨五入

https://ching119.pixnet.net/blog/post/59675573arrow-up-right

preventDefault

防止url直接開啟,如:download

https://www.w3school.com.cn/jquery/event_preventdefault.asparrow-up-right

Last updated