我有以下 javascript 来确定版权格式是否正确:
var copyright = $('#copyright')
var copyright_text = copyright[0].value
if (copyright_text.length > 0) {
var containsYear = /\d{4}/.test(copyright_text);
if (containsYear == false) {
copyright.css({
'background-color': 'rgba(230, 89, 78, 0.07)',
});
copyright.parent().append(
'<div class="explanatory caution">CAUTION: Make sure this copyright contains a year.</div>'
);
};
};
.blur()
如果不从上面复制和粘贴所有代码,我将如何将相同的逻辑应用于上面的正常页面加载?