2012-11-02 167 views
0
var matcheduserID = $('.checkone')[1].matcheduserID; 

<input type="checkbox" matcheduserID='user1' class="checkone" onclick="javascript:HoldItem('H')"> 

此代碼在Internet Explorer中工作,但在Firefox和Chrome中,我得到它返回undefined。jQuery代碼不適用於Firefox/Chrome

+0

LT屬性與類 「checkone」 有多個元素?你的jQuery代碼是否包含在document.ready中?我們能看到更多的代碼來弄清楚嗎? – user1026361

回答

2

我認爲你正在試圖訪問錯誤的元素擺在首位.. 你試圖訪問First element or the second element ..

節點列表是基於0指數。

如果這是您要訪問,然後使用第一個元素

var matcheduserID = $('.checkone')[0].matcheduserID; 

嘗試使用.getAttribute()方法

獲得(1)獲取第二個元素與給定的類..

var matcheduserID = $('.checkone').get(1).getAttribute("matcheduserID"); 

也許你遇到了這個問題,因爲matcheduserID不是defau爲元素

jQuery的

var matcheduserID = $('.checkone:eq(1)').attr('matcheduserID'); 
+0

正確,並使用.get(0)如果只有1個元素而不是[1] – sdespont

+0

爲什麼yall會殺死jQuery?它就像'var matcheduserID = $('。checkone')。attr(「matcheduserID」)一樣簡單' – SpYk3HH

2

我認爲你正在嘗試做這個

matcheduserID = $('.checkone:first').attr('matcheduserID'); 
相關問題