本文給大家分享了幾個(gè)常用的jQuery代碼,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
1.查看瀏覽器信息
- navigator.userAgent
檢索瀏覽器信息包括哪些字符
例如:
- if (navigator.userAgent.toLowerCase().indexOf("htc") >= 0) {
- $("#GuanKa .page_content").css("transform", "scale(0.92)");
- $(".gaunka_pic").css("top", "-100px");
- $(".ertongji_btn").css("top", "570px");
- }
2.給鏈接設(shè)置參數(shù),再根據(jù)url參數(shù)做相應(yīng)的事情
- //用戶當(dāng)天還沒上傳圖片
- $(".Js_uplaod_bnt").click(function () {
- if ($(this).attr("myid") == "1") {
- SiteFunc.Ga('選擇騎騎寶');
- }
- else if ($(this).attr("myid") == "2") {
- SiteFunc.Ga('選擇睡睡寶');
- }
- else if ($(this).attr("myid") == "3") {
- SiteFunc.Ga('選擇踢踢寶');
- }
- else if ($(this).attr("myid") == "4") {
- SiteFunc.Ga('選擇爬爬寶');
- }
- else if ($(this).attr("myid") == "5") {
- SiteFunc.Ga('選擇學(xué)習(xí)寶');
- }
- else if ($(this).attr("myid") == "6") {
- SiteFunc.Ga('選擇走走寶');
- }
- window.location.href = "Upload.aspx?BabyPostureID=" + $(this).attr("myid");
- });
- //點(diǎn)擊上傳Icon圖片的顯示
- var CurBabyPostureID = Cmn.Func.GetParamFromUrl("BabyPostureID");
- $(".Js_photo_icon_upimg img").attr("src", "images/result/photo_icon" + CurBabyPostureID + ".png");
3.手機(jī)端長(zhǎng)按觸發(fā)事件
- //某一元素長(zhǎng)按了2秒就跳轉(zhuǎn)到一個(gè)頁(yè)面
- var _timeout = null;
- //長(zhǎng)按二維碼跳轉(zhuǎn)到辦卡也
- $(".Js_LongPressToCard").on("touchstart",function () {
- window.clearTimeout(_timeout);
- _timeout = setTimeout(function () {
- window.location.href = "https://mbank.spdbccc.com.cn/creditcard/indexActivity.htm?data=000501";
- }, 2000);
- });
- $(".Js_LongPressToCard").on("touchend", function () {
- window.clearTimeout(_timeout);
- });
以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
新聞熱點(diǎn)
疑難解答
圖片精選