2012-11-27 34 views
3

工作,我有一個類型的控制文本框我已經添加財產的inputType驗證文本框在任何瀏覽器無法正常工作,但在IE

和made javascript file to validate t從文本

這裏是正文

<tc1:AppTextBox ID="txtAccNo" runat="server" InputType="Integer" IsPrimary="true" 
IsDatabaseField="true" AllowNull="true"> 
</tc1:AppTextBox> 

這裏我的JavaScript代碼的代碼,他輸入文本

function DoControlBlure(obj) { 
var numVal = obj.value * 1; //To Convert String Value of obj.value to numeric Value 
var bRes = true; 
if (obj) { 
if (obj.type == "text") { 
if (obj.InputType.toUpperCase() == "INTEGER" || obj.InputType.toUpperCase() ==DOUBLE") { 
alert('obj.InputType');}}}} 

在IE中返回,我把實際的輸入類型,但在任​​何其他瀏覽器,它警告undefind 它工作正常,在IE瀏覽器,但在谷歌Chrome或Firefox它的劑量在所有

+0

上面的代碼將只提醒的''obj.InputType''字符串,而不是obj.InputType'的'價值。我不知道你是否正確地發佈/輸入了你的代碼(in)? – Pebbl

回答

0

無法正常工作,您應該使用getAttribute獲得非標在跨瀏覽器的安全的方式DOM元素的attribtues:

<input id="test" InputType="test" /> 

<script> 
    window.onload = function(){ 
    var input = document.getElementById('test'); 
    alert(input.InputType); /// will work in IE, fail in others 
    alert(input.inputtype); /// will fail in all I think? 
    alert(input.getAttribute('InputType')); /// will work in all 
    alert(input.getAttribute('inputtype')); /// should work in all 
    } 
</script> 
相關問題