【问题标题】:Validating Text Boxes from javascript dos not work in any browser but work in IE从 javascript 验证文本框在任何浏览器中都不起作用,但在 IE 中起作用
【发布时间】:2012-11-27 12:46:30
【问题描述】:

我有一个 textbox 类型的控件,我已将 property 添加到其中 输入类型

并制作javascript文件以验证来自文本框

这里是正文的代码

<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 中运行良好,但在 google chrome 或 firefox 中它根本不起作用

【问题讨论】:

  • 上面的代码只会提醒'obj.InputType'的字符串,而不是obj.InputType的值。我不知道您是否已正确发布/输入您的代码?

标签: javascript asp.net html


【解决方案1】:

您应该使用getAttribute 以跨浏览器安全的方式获取 DOM 元素的非标准属性:

<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>

【讨论】:

    猜你喜欢
    • 2017-04-20
    • 2011-04-24
    • 1970-01-01
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 2014-06-13
    相关资源
    最近更新 更多