2017-04-14 102 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