2012-11-27 41 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> 
相关问题