Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对象或属性不受支持_Javascript_Jquery_Internet Explorer 8 - Fatal编程技术网

Javascript 对象或属性不受支持

Javascript 对象或属性不受支持,javascript,jquery,internet-explorer-8,Javascript,Jquery,Internet Explorer 8,我正在尝试将库中的黑客行为标准化,以使用JavaScript定制一个非常难以编写客户端代码的企业平台。基本上,我正在尝试做的是,允许用户传入对他们想要的数据的引用,并且无论数据是如何存储的,我将尝试使用一些预定义的方法来获取它。我知道这个过程并不完美,但对于我们正在尝试做的事情,没有任何替代方案 我使用的是jQuery1.6.2,由于其他库的依赖性,我不得不使用它 以下一行: if($('input[id^='+lineItemAttributeId+']).length>0){ 给出以下错误:

我正在尝试将库中的黑客行为标准化,以使用JavaScript定制一个非常难以编写客户端代码的企业平台。基本上,我正在尝试做的是,允许用户传入对他们想要的数据的引用,并且无论数据是如何存储的,我将尝试使用一些预定义的方法来获取它。我知道这个过程并不完美,但对于我们正在尝试做的事情,没有任何替代方案

我使用的是jQuery1.6.2,由于其他库的依赖性,我不得不使用它

以下一行:

if($('input[id^='+lineItemAttributeId+']).length>0){

给出以下错误:对象不支持IE8中的此属性或方法,但不支持其他平台

Services.prototype.getAttributeValue = function(docNum, variableName, defaultValue) {
  if (docNum == "1") {
    var quoteItemAttributeId = variableName;
    if ($('input[id*=' + quoteItemAttributeId + ']').length > 0) {
      return $('input[id*=' + quoteItemAttributeId + ']').val();
    } else if ($('textarea[id*=' + quoteItemAttributeId + ']').length > 0) {
      return $('textarea[id*=' + quoteItemAttributeId + ']').val();
    } else if ($('select[name*=' + quoteItemAttributeId + ']').length > 0) {
      return $('select[name*=' + quoteItemAttributeId + ']').find("option:selected").val();
    } else {
      return defaultValue;
    }
  } else {
    var lineItemAttributeId = docNum + "_" + variableName;
    if ($('input[id^=' + lineItemAttributeId + ']').length > 0) {
      return $('input[id^=' + lineItemAttributeId + ']').val();
    } else if ($('textarea[id*=' + lineItemAttributeId + ']').length > 0) {
      return $('textarea[id*=' + lineItemAttributeId + ']').val();
    } else if ($('select[name*=' + lineItemAttributeId + ']').length > 0) {
      return $('select[name*=' + lineItemAttributeId + ']').find("option:selected").val();
    } else {
      return defaultValue;
    }
  }
};
我试过:

if($('input[id='+lineItemAttributeId+']).length>0){

if($('input[id*='+lineItemAttributeId+']).length>0){

结果相似


知道我做错了什么吗?

一般来说,使用jQuery属性选择器最安全的方法是将内部参数用引号括起来,特别是当它可以动态赋值时。这可以解释由空格、特殊字符或其他可能导致jQuery语句在根据规则,不带引号的格式仅适用于(可靠地)单个单词字符串。因此,将属性等于选择器替换为:
$('input[id=“”+lineItemAttributeId+”]).length

您使用的是哪个版本的jQuery?jQuery 2.x不支持IE8及更早版本。如果您需要支持较旧的浏览器,则应使用jQuery 1.x。如果($('input[id=“'+lineItemAttributeId+'”).length>0)(注意在内部参数周围添加的双引号)。这通常是使用属性选择器最安全的方法,以避免意外或不需要的奇怪字符导致问题。该小提琴在IE8中对我有效。
lineItemAttributeId
。@n似乎已经做到了这一点的书籍。你能回答问题,从而获得分数吗?