gpt4 book ai didi

javascript - 从 获取值

转载 作者:行者123 更新时间:2023-11-29 22:46:08 25 4
gpt4 key购买 nike

friend 们,我想得到的或者只是知道它是否存在,有没有人有想法?

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="stacks.css?v=f956aeec157c" >
<link rel="stylesheet" type="text/css" href="primary.css?v=f68ca0e24c3b" >

</head>

<body>


<link extension-installed="0318648714777">


<p>Click the button to find out how many <link> elements.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
var x = document.getElementsByTagName("link");

document.getElementById("demo").innerHTML = x.length;
}
</script>
</pre>

不幸的是它计算了所有页面

最佳答案

使用 querySelector使用选择器字符串 body > link找到一个 <link>直接在体内:

function myFunction() {
const link = document.querySelector('body > link');
console.log(link);
console.log(link.getAttribute('extension-installed'));
}
</style>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="stacks.css?v=f956aeec157c">
<link rel="stylesheet" type="text/css" href="primary.css?v=f68ca0e24c3b">

<style>
<link extension-installed="0318648714777">


<p>Click the button to find out how many
<link> elements.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

如果它不是主体的直接子级,请使用 body link取而代之的是获取正文内任何位置的链接。

关于javascript - 从 <link> 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58535161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com