我需要像 .load() 这样的东西,但它只能用于图像和 iframe。我想这样做是为了在“this”变量中自动附加一个选择器元素。
$('document').ready(function({
$('a').<Something to automatically run the stuff below when page is loaded>(function(){
// Placeholder is to store the href somewhere so the link does not go to a webpage atm.
$(this).attr('placeholder',$(this).attr('href'));
$(this).attr('href','javascript:');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="www.example.com">My Link</a>
我不确定你是否想实现这个简单的事情?:
$('document').ready(function({
$('a').each(function(){
$(this).attr('placeholder',$(this).attr('href'));
$(this).attr('href','javascript:');
});
});
$('element').each允许循环遍历所有元素,您可以在闭包中使用$(this)来修改元素本身。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句