簡體   English   中英

如果文本框名稱在字符串變量中,如何獲取clientID

[英]How to get clientID if textbox name is in string variable

我寫下面的代碼來檢查我的文本框中的空白值但是它生成編譯錯誤,請給我解決方案。

我在javascript中的代碼:

 function checkTextboxNotFilled(txtbox) {
        var txtb = document.getElementById("<%= " + txtbox + ".ClientID %>");
        if (GetFormattedString(txtb.value) == "") {
            return true ;
        }
        else {
            return false ;
        }
    }

錯誤:

'string' does not contain a definition for 'ClientID' and no extension method 'ClientID' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

我這樣稱呼它:checkTextboxNotFilled(“MytextboxName”)

這可能對您有所幫助。

 function checkTextboxNotFilled(txtboxid) {
        var txtb = document.getElementById(txtboxid);
        if (GetFormattedString(txtb.value) == "") {
            return true ;
        }
        else {
            return false ;
        }
    }

並調用: checkTextboxNotFilled("<%= Mytextbox.ClientID %>");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM