<xmp>//动态添加html元素后,重新解析样式
$.parser.parse([select]);</xmp>
<xmp>//动态引入外部添加css
$(`<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@baby7305/jquery-easyui@1.9.15/themes/icon.css">`).appendTo("head");</xmp>
<xmp>//动态添加div
function create_div(sid, cls = "")
{
let htmlStr = `<div id="${sid}" ${sid} class="${cls}"></div>`;
$(htmlStr).appendTo("body");
}</xmp>
<xmp> //扩展jQuery
$.extend({
//添加样式$.addStyle(css code/css url)
addStyle: function (css)
{
//判断css是代码还是文件
let is_url = false;
{
var tryStr = css.toLowerCase();
is_url = tryStr.indexOf("http://") == 0 || tryStr.indexOf("https://") == 0;
}
if (!is_url) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) {
console.error("没有找到head");
return;
}
style = document.createElement('style');
style.innerHTML = css;
head.appendChild(style);
} else {
$("head").append(`<link rel="stylesheet" href="${css}">`);
}
},
//在body中添加元素
addElement: function (element)
{
$(element).appendTo("body");
},
//id选择器 $.id("xxx")
id: function (idstr)
{
return $(`#${idstr}`);
}
})</xmp>
1