简体   繁体   English

IE11无法获取未定义或空引用的属性“值”

[英]IE11 Unable to get property 'value' of undefined or null reference

it's seems that I'm having a frustrating problem and can't seem to find an answer. 看来我遇到了一个令人沮丧的问题,似乎找不到答案。 I'm trying to get the value of the element in <td> tag. 我正在尝试获取<td>标记中元素的值。 The id reaches the function but for some reason I can't get the value of it. id到达函数,但由于某种原因我无法获取它的值。

JS JS

function f(id)
  {
    console.log(id);
    expr=/ /gi;
    value = document.getElementById(id).value;
    value = value.replace(expr, "");

  //remaining code
  }

PHP 的PHP

print "<td style=\"height:20px;\"><input $disbled type=\"text\" name=\"".$values[$i][0]."\" onChange=\"return f('".$values[$i][0]."')\" value=\"".$values[$i][1]."\" class=\"".$values[$i][2]."\"></td>\n"; 

Any help would be appreciated! 任何帮助,将不胜感激!

A couple of problems there: 那里有两个问题:

  1. Your element doesn't have an id at all 您的元素根本没有id

  2. Your code is falling prey to The Horror of Implicit Globals (that's a post on my anemic little blog) . 您的代码成为“隐式全球性恐怖”的牺牲品(这是我贫乏的小博客上的帖子)

Here's a fixed version: 这是固定版本:

function f(name)
{
    console.log(name);
    var expr=/ /gi;
    var value = document.querySelector('[name="' + name + '"]').value;
    value = value.replace(expr, "");
    //remaining code
}

#1 is fixed by using querySelector and an attribute selector selecting by name 通过使用querySelector和按name选择的属性选择器来固定#1

#2 is fixed by declaring the local variables in f #2通过在f声明局部变量来固定

You could also fix #1 by giving your element an id and sticking with getElementById . 您还可以通过给元素一个id并坚持使用getElementById来修复#1。

The input you are trying to access has not ID property defined. 您尝试访问的输入未定义ID属性。 You shall add it in order to access the input object via getElementById(). 您应该添加它以便通过getElementById()访问输入对象。

<input $disbled id=\"".$id."\" type=\"text\" name=\"".$values[$i][0]."\" onChange=\"return f('".$values[$i][0]."')\" value=\"".$values[$i][1]."\" class=\"".$values[$i][2]."\">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SCRIPT5007:无法在 IE11 中获取未定义或空引用的属性“值” - SCRIPT5007: Unable to get property 'value' of undefined or null reference in IE11 Angular2 IE11 无法获取未定义或空引用的属性“应用” - Angular2 IE11 Unable to get property 'apply' of undefined or null reference 无法获取未定义或空引用的属性“应用”-IE11和Chrome - Unable to get property 'apply' of undefined or null reference - IE11 and Chrome AG-Grid在IE11中具有vue错误挂接钩中出现错误:“ TypeError:无法获取未定义或空引用的属性&#39;addEventListener&#39; - AG-Grid with vue error in IE11 Error in mounted hook: “TypeError: Unable to get property 'addEventListener' of undefined or null reference” IE 11无法获取未定义或空引用的属性“长度” - IE 11 Unable to get property 'length' of undefined or null reference 无法获取未定义或空引用的属性“top”(IE 11) - Unable to get property 'top' of undefined or null reference (IE 11) 无法在IE 11中获得未定义或空引用的属性“样式” - Unable to get property 'style' of undefined or null reference in IE 11 在Win7上使用IE11的Javascript运行时错误:无法设置未定义或空引用的属性“禁用” - Javascript runtime error using IE11 on Win7: Unable to set property 'disabled' of undefined or null reference 无法获取未定义或空引用IE的属性 - Unable to get property of undefined or null reference IE 无法获取未定义或空引用IE 11 ASP.NET的属性&#39;stringify&#39; - Unable to get property 'stringify' of undefined or null reference IE 11 ASP.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM