我已经使用jQuery Mobile的,我已经得到了以下简单的问题一个页面:jQuery的不删除元素
与DOM的某处(单)链接的页面时:
<a data-theme="a" data-role="button" href="https://m.mybet.com">
Smartphone-Version nutzen</a>
我加入这样一个按钮HTML
<input type="button" onclick="javascript:remove_link();"/>
我的JavaScript看起来像这样:
<script type="text/javascript">
function remove_link() {
console.log("1")
$("a").remove();
console.log("2")
}
</script>
但是,单击该按钮时,Chrome浏览器告诉我:
Uncaught TypeError: Cannot call method 'remove' of null
remove_link
onclick
我也尝试空()来代替,同样的问题。为什么?
小心创建[fiddle](http://jsfiddle.net)? – Chandranshu
是正确包含在页面中的jQuery?如果你在控制台输入$('a'),你会得到什么? – opalenzuela
它在这里工作:http://jsfiddle.net/Q7kJd/ – melancia