You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.3 KiB

document.addEventListener('DOMContentLoaded', function() {
const links = document.querySelectorAll('.nav-pills .nav-link');
// Get the current page path
const currentPath = window.location.pathname;
links.forEach(link => {
// Compare the link's href with the current path
if (link.href.endsWith(currentPath)) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
});
function showModal(message) {
// 设置 Modal 中的消息
document.getElementById('modalMessage').innerText = message;
// 显示 Modal
const responseModal = new bootstrap.Modal(document.getElementById('responseModal'));
responseModal.show();
}
//动态填充select控件
function set_select_data(select_ele_id,datas){
const select_Ele = document.getElementById(select_ele_id);
//清空老数据
select_Ele.innerHTML = '';
//添加列表
datas.forEach(option => {
const optionElement = document.createElement('option');
optionElement.textContent = option;
select_Ele.appendChild(optionElement);
});
}
//设定选项选中状态---下拉框
function set_select_selct(select_ele_id,option_str){
let bfind = false;
const select_Ele = document.getElementById(select_ele_id);
for(let i=0;i< select_Ele.options.length;i++){
if(select_Ele.options[i].value === option_str){
select_Ele.options[i].selected = true;
bfind = true;
break;
}
}
return bfind;
}
//设定单选按钮选中状态 ----单选按钮
function set_radio_selection(groupName, targetValue) {
// 获取所有同名的 radio 按钮
const radios = document.getElementsByName(groupName);
// 遍历 radio 按钮
for (const radio of radios) {
if (radio.value === targetValue) {
radio.checked = true; // 选中匹配项
return true; // 返回成功
}
}
console.error(`未找到值为 ${targetValue} 的 radio 按钮`);
return false; // 未找到匹配项
}
// 获取选中值--返回的value值 ----单选按钮
function get_radio_value(groupName) {
return document.querySelector(`input[name="${groupName}"]:checked`)?.value;
}
//将输入框内容转换为单精度型,若转换失败则返回0 -- 若需要整型,parseInt
function getInputValueAsFloat(id) {
var value = document.getElementById(id).value;
return value ? parseFloat(value) : 0;
}
//正则匹配IP是否合法 return true,false
function isValidIP(ip) {
const ipRegex = /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$/;
return ipRegex.test(ip);
}
//post提交JSON数据
function postJson(url,data){
}
//post提交From数据 -- 返回数据是JSON
function postFrom(url,data){
fetch(url, {
method: 'POST',
body: data,
})
.then(response => response.json())
.then(data => {
const istatus = data.status;
alert(data.msg);
if(istatus == 1 ){
fetchModelData();
$('#updateMM').modal('hide');
}
})
.catch(error => {
console.error('Error:', error);
alert('升级失败,请重试。');
btn.disabled = false;
});
}
//get请求数据
function getDATA(url){
}