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/
https://blog.reh.tw/archives/662
介紹
https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/272853/
success and error
http://www.pureexample.com/tw/jquery/ajax-success-and-error.html
另一種post寫法 (尚未與ajax比較)
https://stackoverflow.com/questions/18697034/how-to-pass-parameters-in-ajax-post/35590754
傳送json資料 (400)
https://stackoverflow.com/questions/21738663/getting-json-in-flask-from-jquery-ajax
用enter送出
https://www.formget.com/submit-your-form-on-pressing-enter-key-using-jquery/
https://stackoverflow.com/questions/699065/submitting-a-form-on-enter-with-jquery
json物件處理
使用ajax post時可用JSON.stringify()轉換型態後再傳送
使用ajax get接收回傳結果時可用JSON.parse()轉換型態
https://www.w3schools.com/js/js_json_parse.asp
遍歷方法
https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/258763/
https://t.codebug.vip/questions-342113.htm
替換特殊字元(換行、雙引號)
日期選擇器
http://www.daterangepicker.com/
https://www.wfublog.com/2017/08/jquery-date-range-picker-bootstrap.html
https://dotblogs.com.tw/shadow/2017/11/28/001719
取得check box值
http://blog.twbryce.com/jquery-get-checkbox-value/
常用語法
checkbox 全選
http://dev.sopili.net/2013/03/bootstrap-css.html
cdn介紹
https://blog.csdn.net/zyz1985/article/details/6828790
string 格式化
https://www.cnblogs.com/taoweiji/p/3260883.html
radio
https://blog.csdn.net/enjoyo/article/details/1700228
select
取值
http://n.sfs.tw/content/index/10047
onload vs ready
ready,表示文件結構已經載入完成(不包含圖片等非文字媒體檔案)
onload,指示頁 麵包含圖片等檔案在內的所有元素都載入完成。
ready 在onload 前載入!!!
https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/290536/
function
https://melomelo1988.pixnet.net/blog/post/263934328
https://matthung0807.blogspot.com/2017/11/jquery-document-ready.html
button事件觸發
https://www.w3school.com.cn/jquery/jquery_ref_events.asp
https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/232048/
window.onload vs $(document).ready
ready:DOM下載完成就觸發function,啟動時機較早,前一次跟後一次所設定的函式都會被執行。
onload:除了DOM,連同其中的圖片影音的內容都下載完才會觸發function,啟動時機較晚,後一次所設定的函式會複寫上一次的。
https://ithelp.ithome.com.tw/articles/10092601
https://matthung0807.blogspot.com/2017/11/jquery-document-ready.html
複寫
onload只會執行第二個,第一個會被忽略
setInterval
https://neohsuxoops.blogspot.com/2018/04/ajaxfunction.html
https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/276882/
.html() .text() .val()
http://androchen.blogspot.com/2013/04/jquery-html-text-val.html
jQuery equivalent to “getElementsByName”
https://stackoverflow.com/questions/9711917/jquery-equivalent-to-getelementsbyname
更新CSS
全域變數 vs 區域變數
1.變數宣告在function外面,不管有沒有加上var都是全域變數
2.變數宣告在function之內,沒有加上var就會成為全域變數
https://engmeter.blogspot.com/2015/03/jqueryjquery.html
settimeout
confirm
https://www.w3schools.com/jsref/met_win_confirm.asp
textarea 的取值和給值
http://n.sfs.tw/content/index/10044
https://www.w3schools.com/tags/tag_textarea.asp
onchange event for input type=“number”
https://stackoverflow.com/questions/9609731/onchange-event-for-input-type-number
四捨五入
https://ching119.pixnet.net/blog/post/59675573
preventDefault
防止url直接開啟,如:download
Last updated
Was this helpful?