使用JavaScript编写以下代码,将窗口中的主机名删除。
const hostname = window.location.hostname; // 获取主机名
const alertMessage = 'This is your alert message with the hostname: ' + hostname;
alert(alertMessage);
// 移除主机名
const alertBox = document.querySelector('div[role="alert"]');
const alertText = alertBox.textContent;
const modifiedText = alertText.replace(hostname, '');
alertBox.textContent = modifiedText;
上一篇:Alert策略未能创建事件