我对 JavaScript 或 jQuery 没有太多经验。
我尝试使用 Tampermonkey 自动更正 MAC 地址的输入字段。
该站点需要一个格式为00:00:00:00:00:00.
所以我为 Tampermonkey 编写了这个脚本,以便在我输入时它会自动添加冒号:
// ==UserScript==
// @name Name
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adds colons to the mac adress of the Mac Field
// @author You
// @match Somesite
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
document.getElementById("MAC").addEventListener('keyup', function() {
var mac = document.getElementById('MAC').value;
var macs = mac.split('');
var colons = ["2", "5", "8", "11", "14"];
for (var col in colons) {
if (macs[col] …Run Code Online (Sandbox Code Playgroud)