0
查找html字符並縮小大小,不確定該功能是做什麼的?在整個網站中查找html字符並減小尺寸
jQuery("body").children().each(function() {
jQuery(this).html(jQuery(this).html().match("•").attr('style', "font-size:'9px'"));
});
查找html字符並縮小大小,不確定該功能是做什麼的?在整個網站中查找html字符並減小尺寸
jQuery("body").children().each(function() {
jQuery(this).html(jQuery(this).html().match("•").attr('style', "font-size:'9px'"));
});
至於評論,
你將不得不樣式設置爲元素,而不是字符串。
要做到這一點,你必須獲取字符串,然後將匹配的字符串包裝到具有必要樣式的元素中。
在您的代碼jQuery(this).html().match("•").attr('style', "font-size:'9px'")
,.match
將返回匹配值的數組。它們仍然是字符串,而不是HTML元素。
樣品
document.getElementById("btn").addEventListener("click", handleClick);
function handleClick(){
var input = document.getElementById("input").value;
if(!input) return;
var p = document.querySelector("p");
var parsed = p.innerHTML.replace(new RegExp(input, "gi"), function(t){
return "<span class='highlight'>" + t + "</span>"
});
p.innerHTML = parsed;
}
.highlight{
font-size: 12px;
border-bottom: 1px dashed gray;
}
span{
font-size: 16px;
}
<p> This is a sample Text</p>
<input type="text" id="input" />
<button id="btn">Update Style</button>
您不能分配樣式文本。它必須分配給一個元素 – Rajesh
該CSS必須是元素。添加div。 – Firemen26
@roshambo打開你的控制檯,它是大喊大叫的錯誤。 'jQuery(...)。html(...)。match(...)。attr不是一個函數'。 –