[英]HTML and Javascript button to make text in a textarea bold and unbold, Possibly using JQuery?
我目前有一个按钮,可以使它使用的文本区域中的文本变为粗体
<a href="#" class="stylingButtons" type="button" onclick="boldTextArea()" value="Bold Text"}>
<img alt='Bold Button' src='BButton.gif' border='4' width="90px" >
</a>
对于HTML部分,
function boldTextArea(){
document.getElementById("TextArea").style.fontWeight="bolder";;
}
对于javascript
无论如何,我是否可以编辑此编码,以便一旦文本区域中的文本已经为粗体,就可以再次单击以使其变为粗体? 我真的不热衷于使用jQuery,因为我从没有过使用它的经验,但是我愿意接受这种格式的建议吗?
如果您不想使用jquery,这是一个快速的'n'dirty javascript
function boldText(){
var target = document.getElementById("TextArea");
if( target.style.fontWeight == "bolder" ) {
target.style.fontWeight = "normal";
} else {
target.style.fontWeight = "bolder";
}
}
应该工作正常。 我猜这是从大胆切换到正常再返回的基本方式。
也请注意DOUBLE“;” 在您的JS中。
希望这可以帮助。
gr Ace
更新
这是jQuery版本,可在每次点击时更改(切换)文本大小(或任何其他css属性)。
$("#textboxid").click( function(e) {
if( $(this).css("font-size") == "12px" ) {
$(this).css("font-size", "14px")
} else {
$(this).css("font-size", "12px")
}
});
如果要更改任何其他属性,请将css属性替换为您喜欢的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.