我想使用以下范围的小时来设置早上/晚上/下午/夜间的范围:
Good Evening: 16:00 to 23:00
Good Morning: 4:00 to 11:59
Afternoon: 12:00
Good Afternoon: 12:00 to 16:00
HTML代码:-
<!DOCTYPE html>
<html>
<head>
<title>Greeting Message using JavaScript</title>
</head>
<body>
<label id="Greetings"></label>
</body>
<script>
document.write("<h2>");
var day = new Date();
var hr = day.getHours();
if (hr >= 4 && hr < 12) {
document.write("Good Morning");
} else if (hr == 12) {
document.write("Afternoon");
} else if (hr >= 12 && hr <= 16) {
document.write("Good Afternoon");
} else if (hr >= 16 && hr <= 23) {
document.write("Good Evening");
} else {
document.write("Good Night");
}
document.write("</h2>");
</script>
</html>
答案1
您仍然可以使用 Internet Explorer COM 对象来处理 HTML 代码:
# start internet explorer COM
$ie = New-Object -COM 'InternetExplorer.Application'
# load your html
$ie.Navigate('file://C:\test\test.html')
# Get the output of a particular node, based on your example:
$ie.Document.body.childNodes |
Where NodeName -eq 'H2' |
Select -ExpandProperty InnerText
Good Evening
# dispose of the IE object
$ie.Quit()
请注意,您可能需要更改 ActiveX 安全设置才能执行<script>
。因此,如果您的 jscript 无法运行,请尝试使 IE 可见:$ie.Visible = $true
,刷新,然后检查 ActiveX 警告。
https://devblogs.microsoft.com/scripting/how-can-i-tell-if-activex-is-enabled-in-internet-explorer/