跳转链接,提交时,ajax方式将对方手机号,提交到post地址,然后存储继续跳转不同的申卡链接地址即可,然后css优化下tel的输入框,好看些,最好有特效。
<!DOCTYPE html>
<html>
<head>
<title>实时保存并跳转</title>
</head>
<body>
<!-- 修正输入框拼写错误 -->
<input type="text" id="tel" placeholder="请输入电话号码">
<script>
// 获取输入框元素
const telInput = document.getElementById('tel');
// 防抖函数(减少请求频率)
let debounceTimer;
function debounce(func, delay) {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(func, delay);
}
// 输入事件处理
telInput.addEventListener('input', function(e) {
const value = e.target.value;
// 简单电话号码验证(示例)
if (!/^\d*$/.test(value)) {
alert('请输入有效的电话号码');
return;
}
// 防抖处理:用户停止输入500ms后执行
debounce(() => {
// 使用 Fetch API 发送请求
fetch('https://api.example.com/save-tel', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ telephone: value })
})
.then(response => {
if (!response.ok) {
throw new Error('网络响应异常');
}
return response.json();
})
.then(data => {
console.log('保存成功:', data);
// 跳转到新页面(替换成你的目标URL)
window.location.href = 'https://example.com/next-page';
})
.catch(error => {
console.error('保存失败:', error);
// 可以添加错误提示逻辑
});
}, 500);
});
</script>
</body>
</html>
发表回复