前端添加
进入/themes/default目录找到website.html,在最底部的{#include file="footer.html"#}上面加入以下代码
<script>
// DOM加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
const urlInput = document.getElementById('web_url');
// 实时输入处理
urlInput.addEventListener('input', function(e) {
this.value = sanitizeURL(this.value);
});
// 失焦时最终校验
urlInput.addEventListener('blur', function(e) {
this.value = finalCheckURL(this.value);
});
});
// 即时清理函数
function sanitizeURL(url) {
return url
.replace(/^s+/, '') // 去除首部空格
.replace(/^(https?|ftp):///i,'') // 移除协议头
.replace(/^/+/g, '') // 移除开头的斜杠
.replace(/s+/g, '') // 移除所有空格
.replace(//+/g, '/'); // 合并多余斜杠
}
// 最终校验函数
function finalCheckURL(url) {
const cleaned = sanitizeURL(url)
.replace(//+$/g, '') // 去除末尾斜杠
.trim();
// 添加自定义校验逻辑(示例)
if (!cleaned) {
console.warn('URL不能为空');
}
return cleaned;
}
</script>
后端添加
进入/themes/system目录找到website.html,在最底部的{#include file="footer.html"#}上面加入以下代码
<script>
// DOM加载完成后执行
document.addEventListener('DOMContentLoaded', function() {
const urlInput = document.getElementById('web_url');
// 实时输入处理
urlInput.addEventListener('input', function(e) {
this.value = sanitizeURL(this.value);
});
// 失焦时最终校验
urlInput.addEventListener('blur', function(e) {
this.value = finalCheckURL(this.value);
});
});
// 即时清理函数
function sanitizeURL(url) {
return url
.replace(/^s+/, '') // 去除首部空格
.replace(/^(https?|ftp):///i,'') // 移除协议头
.replace(/^/+/g, '') // 移除开头的斜杠
.replace(/s+/g, '') // 移除所有空格
.replace(//+/g, '/'); // 合并多余斜杠
}
// 最终校验函数
function finalCheckURL(url) {
const cleaned = sanitizeURL(url)
.replace(//+$/g, '') // 去除末尾斜杠
.trim();
// 添加自定义校验逻辑(示例)
if (!cleaned) {
console.warn('URL不能为空');
}
return cleaned;
}
</script>