HTML DOM 链接的 size 属性
htmlweb developmentfront end technology更新于 2025/7/16 1:16:17
HTML DOM 链接的 size 属性返回链接元素的 size 属性值。
注意− 仅当 rel 属性设置为 ‘icon’ 时,sizes 属性才有效。
语法
以下是语法 −
返回 sizes 属性值
linkObject.sizes
示例
让我们看一个 Link rel 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Link sizes</title>
<link id="extStyle" rel="icon" href="new.gif" sizes="10x10">
</head>
<body>
<form>
<fieldset>
<legend>Link-sizes</legend>
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var extStyle = document.getElementById("extStyle");
if(extStyle.sizes == '10x10')
divDisplay.textContent = 'The linked icon size: '+extStyle.sizes+' is not compatible';
else
divDisplay.textContent = 'Congrats! The linked icon size is compatible';
</script>
</body>
</html>
在上面的例子中,‘style.css’ 包含 −
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
输出
这将产生以下输出 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

