2017-04-14 101 views
-1

I'm trying to return the idselection attribute. Every time I run it though I just get a lot of blank spaces. I've tried using the find() method and map() . I just keep getting a lot of blank spaces. The HTML below is an example of what i'm trying to get最后一块拼图

$('.mg-check.mg-checkEmpty.requireLogin').each(function() { 
      var data = $(this).attr('selectionid'); 

      propVal = data; 
      console.log(propVal); 
      json.propVal = propVal; 
     }); 
    } 

<td class="mg-column8 pick borderRight last"> 
    <a class="mg-check mg-checkEmpty requireLogin" id="matchupDiv" name="matchupDiv" href="createOrUpdateEntry?" selectionid="mafdafd"></a> 
+0

您的名字=属性也没有关闭引号。 – Difster

回答

-1

试试这个。

$('.mg-check.mg-checkEmpty.requireLogin').each(function() { 
     var data = $(this).attr('id'); //note the change in this line 

     propVal = data.text(); 
     console.log(propVal); 
     json.propVal = propVal; 
    }); 
} 
+1

我以前试过,它返回一个错误,说 'propVal = data.text(); ^ TypeError:data.text不是一个函数' – tin

+0

:)))))))我想通了!!!!!!这是因为我试图返回的信息不是字符串,所以'text()'不起作用!我一直在为此工作过去3个小时:))) – tin

+0

你知道吗,我甚至没有注意到propVal的结构。 但我很高兴你把它修好了。 – Difster