鍍金池/ 問答/HTML/ js提示Uncaught TypeError怎么解決?

js提示Uncaught TypeError怎么解決?

錯誤提示:
Uncaught TypeError: autopbn.getAttribute is not a function at exauto_ajax_page.js?s1m:10

var autopbn = $('autopbn');
var nextpageurl = autopbn.getAttribute('rel').valueOf();//這句提示Uncaught TypeError: autopbn.getAttribute is not a function at exauto_ajax_page.js?s1m:10
回答
編輯回答
拽很帥

getAttribute是原生的方法,autopdn是jquery對象,無法調用原生方法,用attr("rel")

2017年9月4日 11:47
編輯回答
壞脾滊

樓上說的很清楚了。
autopbn是一個jQuery對象,自然只能使用jQuery的方法,在此文中是.attr('rel')
getAttribute是DOM對象的操作方法,如必須要使用,以下操作即可

var $autopbn = $('autopbn');
var nextpageurl = $autopbn[0].getAttribute('rel').valueOf();

給變量加上$,表明這是個jQuery對象,區(qū)別于DOM對象

2017年6月11日 13:40