2014年8月27日 星期三

jQuery 如何判斷選擇的物件在不在

通常都會先把jQuery每個物件的功能都寫好
但有時在asp.net webform visable = false時就會找不到物件
因為dom裡並沒有所以要判斷一下物件是否存在
var aTag = $('#abc');
if (!aTag.length)
    return;
參考網址
點我前往

2014年8月20日 星期三

jQuery Table Scroll freeze

一整天都測試凍結視窗
試了快六種但都不太好套
StickyTableHeaders這個算不錯但不能凍結column
目前找到最好用的gridviewscroll使用簡單

2014年7月14日 星期一

jQuery window.opener寫法

相信跨頁傳值或控制父頁的元件都是用
window.opener.getElementById("abc").value  = 'abc';
那用jQeury怎麼做??
$('#abc', opener.document).attr("value",txt);
參考網址 點我前往

2014年7月9日 星期三

Bootstrap cannot call methods on button prior to initialization

在Bootstrap中使用button地'load'功能
btn.button('loading');
發生下列問題
cannot call methods on button prior to initialization
網路查了一下,主要是jQuery UI的js檔錯誤,
檢查一下jquery ui的js是不是放於bootstrap的js上面

2014年7月3日 星期四

c# Parameters.AddWithValue DBNull

在Inser or Update時難免遇到的問題
第一個想法會寫個function來判斷DBNull 或是文字
或者是用三元運算子
今天看到更短的寫法順便學一下
cmd.Parameters.AddWithValue("@abc", (object)item.abc ?? DBNull.Value);
參考網址
cmd.Parameters.AddWithValue("@param1",param1 ?? DbNull.Value)

2014年6月26日 星期四

jQueryUI Autocomplete Combobox 修改寬度

jQuery UI 點我進入
找了很多方法居然都改不了
結果只到最簡單的方式才能改
$('.ui-autocomplete-input').css('width', '90%');
參考網址
How to set the width of jQuery ComboBoxes

2014年6月9日 星期一

Visual Studio 2013 Express 只有原始檔無設計

雖然html有些跟本不需看設計畫面
但有些原件必需要看設計畫面才知道怎麼做
工具 > 選項 > HTML設計工具 > 啟用HTML設計工具

參考網址
點我前往

2014年5月28日 星期三

Asp.net MVC Html.ActionLink & Url.Action https(SSL)(18)

記錄一下摟
@Html.ActionLink("關於", "About", "Home", "https", "", "", new { id = "1" ,test="000"}, new { @class="abc"})
@Url.Action("About","Home",null,"https","")

jQuery 將網頁導到https(SSL)

最近都在架構的網站都會走SSL
所以記來以後來會用到
  
        $(function () {
            if (window.location.protocol != "https:") {
                var sslUrl = location.href.replace(/^http/i, "https");
                window.location.href = sslUrl;
                return;
            }
        });
 
參考網站
Detect HTTP or HTTPS then force HTTPS in JavaScript

IIS 免費SSL(StartSSL)

以下兩篇保哥的文章已經算超詳細了
我也是看這兩篇就攪定摟感謝保哥
免費申請 StartSSL™ 個人數位簽章與網站 SSL 憑證完全攻略
如何在 IIS7 / IIS7.5 安裝 SSL 憑證(含 IIS7 匯入憑證的 Bug)

2014年5月12日 星期一

Javascript 呼叫c#function

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"></asp:LinkButton>
 javascript: __doPostBack('<%= LinkButton1.UniqueID %>', '');
參考網址
jQuery call __doPostBack on LinkButton

2014年5月9日 星期五

c# 遮罩電話 xxx

這function效能非最佳只不過目前剛好用到
所以隨手寫了一下
如有更好的方式可提供喔謝謝!!
   /// <summary>
        /// 遮罩電話 (十個字 手機市話)(九個字 市話)(十個字以上前四後三)(四個字以下回傳空白)
        /// </summary>
        /// <param name="pStr">字串</param>    
        /// <returns>string</returns>
        public static string MaskString(string pStr)
        {
            string mReturn = "";

            if (pStr.Length == 9 && pStr.StartsWith("0")) //9碼的如高雄
            {
                mReturn = pStr.Substring(0,2) + "-XXX-" + pStr.Substring(5,4);
            }
            else if (pStr.Length == 10 && pStr.StartsWith("09"))//手機
            {             

                mReturn = pStr.Substring(0, 4) + "-XXX-" + pStr.Substring(7, 3);

            }
            else if (pStr.Length == 10 && pStr.StartsWith("0"))//台北市話
            {
                mReturn = pStr.Substring(0, 2) + "-XXXX-" + pStr.Substring(6, 4);
            }
            else
            {
                if (pStr.Length > 10)//十個字以上
                {
                    for (int i = 0; i < pStr.Length ; i++)
                    {
                        if ((i == 0 || i <= 3) || (i >= pStr.Length - 3)) //前四個字 後三個字出現
                        {
                            mReturn += pStr.Substring(i,  1);
                        }
                        else
                        {
                            mReturn += "X";
                        
                        }
                    }                   
                }
                else  if(pStr.Length >= 4)//四個字以上才會做
                {
                    for (int i = 0; i < pStr.Length; i++)
                    {
                        if (i >= pStr.Length - 3) //後三個字出現
                        {
                            mReturn += pStr.Substring(i, 1);
                        }
                        else
                        {
                            mReturn += "X";
                        }
                    }
                }            
            }
            return mReturn;
        }

2014年4月14日 星期一

T-SQL MS SQL日期相關

以下這篇寫的超清楚的請參考
點我前往
點我前往
以下記錄自己會常用
==========================
日期是否正確
SELECT ISDATE('日')
回傳0錯誤1正確
==========================
目前時間
select GETDATE()
格林威治時間
select GETUTCDATE()
==========================
取得星期幾
SELECT Right(datename(weekday,getdate()),1)
==========================
取得幾天前或幾天後
SELECT DATEADD(day, -3, '2014-08-14')
SELECT DATEADD(day, 3, '2014-08-14')

2014年4月11日 星期五

Asp.net 使用Resource.resx檔 + MVC

我想多國語言大多數的人都會用這個做法吧寫在資源檔
如何叫用如下
在.cs
 Label1.Text = Resources.Resource.名稱;
在aspx
  Text='<%$ Resources:Resource, 名稱%>'
在js or 網頁中
 var StringTimeFormatError = "<%= Resources.Resource.名稱 %>";
alert(StringTimeFormatError );
在MVC 網頁中
@Resources.Resource.名稱 
<system.web>
   <globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>
</system.web>
參考網址
Set the Resource String in javascript
如何讓 App_GlobalResources 裡的全域資源檔變成公開類別

2014年4月3日 星期四

jQueryUI datepicker自訂日期不能選擇

原本以回很難的
因為要用jQuery UI 去指訂某些日期不能選擇
還好網路很方變找的個方法
在beforeShowDay時設定不能用的日期即可範例如下
$("#datae").datepicker({               
        beforeShowDay: setDisableDate //設定日期的function
   });  

   var DisableDate = [];//日期陣列 

 
  //可以用ajax post之類來帶入資料
  //todo

  //設定的function Elaine Wu
  function setDisableDate(date) {
        var strDate = date.getFullYear() + "-" + toTen(date.getMonth() + 1) + "-" + toTen(date.getDate());
        var aryReturn = [true, ""];
        $.each(DisableDate, function (key, value) {
             if (value == strDate) {
                 aryReturn = [false, "", "已設定不能選擇"];
             }
        });
        return aryReturn;
   }

   function toTen(s) {
            return s < 10 ? '0' + s : s;
   }
參考來源
Elaine Wu如何讓datepicker中某些特定日期不可選?
jQuery Datepicker 选择指定日期【转】

2014年4月1日 星期二

jQuery Master-Detail範例

相信Master Detail是很常用的架構
呈現方式百百種
我大多會用fanybox或window.open
因為做起來相當簡單還有
昨天看到一個相當簡單又實用的範例分享給需要的人
點我前往

2014年3月28日 星期五

jQuery go to Top Bottom PageUp PageDown

又來念一下做post機上用網頁系統真麻煩
但還是要克服,用法很簡單
top
$('#top').click(function () {
     $('body,html').animate({ scrollTop: 0 }, 300);
});
bottom
$('#bottom').click(function () {
     $('body,html').animate({ scrollTop: $(document).height() }, 300);
});
PageDown
$('#PageDown').click(function () {
     $('body,html').animate({ scrollTop:  $(window).scrollTop() + 300 }, 300);
});
PageUp
$('#PageUp').click(function () {
     $('body,html').animate({ scrollTop:  $(window).scrollTop() - 300 }, 300);
});

2014年3月27日 星期四

FancyBox 解決gallery模式時next prev檔到scroll bar

點我進入
這個解法官方就有摟
註記一下讓自己不會忘記修改css
.fancybox-nav {
 position: absolute;
 top: 0; 
 /*width: 40%;Marco*/
 width: 60px;
 height: 100%;
 cursor: pointer;
 text-decoration: none;
 background: transparent url('blank.gif'); /* helps IE */
 -webkit-tap-highlight-color: rgba(0,0,0,0);
 z-index: 8040;
}

.fancybox-prev {
 /* left: 0;Marco */
 left: -60px;
}

.fancybox-next {
   /* right: 0; Marco */
  right: -60px;
}

Google Chrome Scroll Bar 變成windows 7 Scroll Bar

最近也在post機上的網頁
但是post機相當舊了裝IE8是可以跑但超慢
於是就找了Chrome來裝但Post機上用網頁操作是有點不方便
尤其是chrome scroll bar相當窄
我以有時會點不到還好找到將Chrome scroll bar變成win 7的外掛程式
使用相當簡單
1.Win7 Scrollbars
2.點 + ADD or + 免費
3.關掉Chrome再開就好
How to restore the vertical scroll bar arrows in Google Chrome