在 anchor 内,这有效:
$(this).prepend('<span>This is the span content</span>');
当尝试执行 if href 等于时,它不起作用
$('a[href="http://www.google.com"]').prepend('<span>You have selected Google</span>');
最佳答案
我已经做了一个示例,没有发现任何错误。
<script>
$(function(){
$("#btn1").click ( function() {
$("a[href='http://www.google.com']").prepend ( "<span>You have selected Google</span>" );
});
});
</script>
<a href="http://www.google.com">Click</a>
<button id="btn1">Click me</button>
<强> Working Demo
关于javascript - jquery anchor 检测和前置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2018249/