[英]Javascript: Can't get element using $('id')
我想使用$('id')访问对象,但无法成功。
这是我的代码:
function jumptopage(myOffset, mySilder, table) { // javascript
...
var oPageSlice = $(recordsPageName); // -> stop
var myURL = $("jumptourl").value; // -> -> stop
...
}
程序总是在这两行停止。 recordsPageName是“ records_page”,“ jumptourl”和“ records_page”确实存在。 我可以使用“ var oPageSlice = document.getElementById(recordsPageName);” 替换为“ var oPageSlice = $(recordsPageName);”
它将起作用。 但是我仍然想找到原因。
ps在下面也可以重现该问题。
在我的php代码中似乎是同样的问题。
html[] = '<input type="button"
onClick="setPerPageRecs($(\''.$this->aName['records_page'].'\')...'
在这种情况下,当我单击按钮时似乎不会调用setPerPageRecs,似乎$(\\''。$ this-> aName ['records_page']。'\\'与该对象不对应。
您需要添加#以通过id获取元素。 像这样:
$("#id");
查看选择器#ID 。 它缺少选择ID的#
$("#jumptourl").val();
我认为$("jumptourl")
是要引用ID还是类?
您需要使用.
代表课程,或#
代表ID。
例如
$(".jumptourl")
或$("#jumptourl")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.