我需要通过 jquery 动态单击链接。
在单击之前,我为该链接设置了一些额外的或新的参数。
$('#add-new-event a:first').attr('href', `/admin/content/events/add/lesson?popup=/day-view&start=2019-10-15T08:00:00&end=2019-10-15T08:15:00&instructor=673`);
$('#add-new-event a:first').click();
console.log($('#add-new-event a:first').attr('href'));
它正确设置了 params,但发送的 params 没有更新,它获得了旧的 params。当 jquery 单击链接时,如何向链接添加新的或额外的参数?
这是一种方法。
$(document).ready(function(){
$('.link').click(function(e){
this.href='/admin/content/events/add/lesson?popup=/day-view&start=2019-10-15T08:00:00&end=2019-10-15T08:15:00&instructor=673';
console.log(this.href);
//use e.preventDefault() to prevent redirect to check updation
});
$('.link')[0].click(); // call click()
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="http://foo.bar" class='link'>click me!</a>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句