改变 HTML 样式 Object.style.property=new style;

改变 HTML 样式

HTML DOM 允许 JavaScript 改变 HTML 元素的样式。如何改变 HTML 元素的样式呢?

语法:

Object.style.property=new style;

注意:Object是获取的元素对象,如通过document.getElementById("id")获取的元素。

基本属性表(property):

注意:该表只是一小部分CSS样式属性,其它样式也可以通过该方法设置和修改。

看看下面的代码:

改变 <p> 元素的样式,将颜色改为红色,字号改为20,背景颜色改为蓝:

<p id="pcon">Hello World!</p>
<script>
   var mychar = document.getElementById("pcon");
   mychar.style.color="red";
   mychar.style.fontSize="20";
   mychar.style.backgroundColor ="blue";
</script>

结果:

任务

现在我们来改变下HTML中元素的CSS样式:

1. 在右边编辑器中,第12行补充代码,修改h2标签的样式,将颜色设为红色。

2. 在右边编辑器中,第13行补充代码,修改h2标签的样式,将背景颜色设为灰色(#CCC)。

3. 在右边编辑器中,第14行补充代码,修改h2标签的样式,将宽设为300px。


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>style样式</title>
</head>
<body>
  <h2 id="con">I love JavaScript</h2>
  <p> JavaScript使网页显示动态效果并实现与用户交互功能。</p>
  <script type="text/javascript">
    var mychar= document.getElementById("con");
    mychar.style.color="yellow";
    mychar.style.backgroundColor:"#CCC";
    mychar.style.width=300px;
  </script>
</body>
</html>



# Windows Server Baseline Scanner.ps1 # 需要管理员权限执行 # 初始化日志文件 $reportPath = "$env:USERPROFILE\Desktop\BaselineReport_$(Get-Date -Format 'yyyyMMdd-HHmmss').html" $currentDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss" # HTML报告模板 $htmlHeader = @" <style> body {font-family: Consolas; margin: 20px} table {border-collapse: collapse; width: 100%} th {background: #004684; color: white; padding: 8px} td {padding: 6px; border: 1px solid #ddd} .warn {background: #FFF3CD} .critical {background: #F8D7DA} </style> <h2>Windows Server 基线扫描报告</h2> 扫描时间:$currentDate<br> 服务器名称:$($env:COMPUTERNAME) <hr> "@ # 1. 系统基础信息 $systemInfo = Get-WmiObject Win32_OperatingSystem | Select-Object Caption, Version, BuildNumber, OSArchitecture, @{Name="LastBootTime"; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}} # 2. 补丁状态检测 (当前/最新) $hotfixes = Get-HotFix | Select-Object HotFixID, InstalledOn, InstalledBy | Sort-Object InstalledOn -Descending $latestPatch = Get-WmiObject -Query "SELECT * FROM Win32_QuickFixEngineering" | Sort-Object InstalledOn -Descending | Select-Object -First 1 # 3. 组件版本检测函数 function Get-ComponentVersions { param($componentName) $output = switch($componentName) { ".NET Framework" { Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version, Release -ErrorAction SilentlyContinue | Where-Object { $_.Version -ne $null } | Select-Object @{n="组件";e={$_.PSChildName}}, @{n="当前版本";e={$_.Version}}, @{n="最新版本";e={[system.version]::new(4,8,0)}} } "PowerShell" { [PSCustomObject]@{ 组件 = "PowerShell" 当前版本 = $PSVersionTable.PSVersion.ToString() 最新版本 = "7.4.1" } } "IIS" { if (Test-Path "HKLM:\SOFTWARE\Microsoft\InetStp") { $iisVersion = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\InetStp" | Select-Object VersionString [PSCustomObject]@{ 组件 = "IIS" 当前版本 = $iisVersion.VersionString 最新版本 = "10.0.20348.1" # Windows Server 2022 IIS版本 } } } } return $output } # 4. 安全基线检查 $securityChecks = @( # 密码策略 @{ 检查项 = "密码最小长度" 当前值 = (Get-LocalSecurityPolicy "MinimumPasswordLength").Value 合规要求 = ">= 8" 状态 = if ((Get-LocalSecurityPolicy "MinimumPasswordLength").Value -ge 8) {"合规"} else {"不合规"} }, # 账户锁定策略 @{ 检查项 = "账户锁定阈值" 当前值 = (Get-LocalSecurityPolicy "LockoutBadCount").Value 合规要求 = "<= 5" 状态 = if ((Get-LocalSecurityPolicy "LockoutBadCount").Value -le 5) {"合规"} else {"不合规"} } ) # 生成HTML报告 ConvertTo-Html -Body $htmlHeader ` -PostContent "<h3>系统信息</h3>", ($systemInfo | ConvertTo-Html -Fragment), "<h3>已安装补丁(最近5个)</h3>", ($hotfixes | Select-Object -First 5 | ConvertTo-Html -Fragment), "<h3>组件版本状态</h3>", (Get-ComponentVersions ".NET Framework" | ConvertTo-Html -Fragment), (Get-ComponentVersions "PowerShell" | ConvertTo-Html -Fragment), (Get-ComponentVersions "IIS" | ConvertTo-Html -Fragment), "<h3>安全基线检查</h3>", ($securityChecks | ForEach-Object { [PSCustomObject]$_ } | ConvertTo-Html -Fragment) ` | Set-Content $reportPath Write-Host "扫描报告已生成:$reportPath" -ForegroundColor Green
04-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值