,可以通过以下步骤实现:
const urlParams = new URLSearchParams(window.location.search);
const paramValue = urlParams.get('paramName');
其中,'paramName'是要获取的参数名。
const divElement = document.getElementById('divId');
divElement.setAttribute('data-param', paramValue);
其中,'divId'是要添加参数的div元素的id。
divElement.scrollIntoView({ behavior: 'smooth' });
其中,{ behavior: 'smooth' }是可选的参数,用于实现平滑滚动效果。
这样,当URL中存在参数时,页面加载后会自动将参数添加到指定的元素,并滚动到该元素所在的位置。
推荐的腾讯云相关产品:腾讯云云服务器(CVM)
领取专属 10元无门槛券
手把手带您无忧上云