如何在js中获取占位符值
how to get a placeholder value in js
如何在 javascript
中获取占位符的值
我不想JQuery获取值
谁能告诉我如何获得它
const ip = document.getElementById("ip").getAttribute('placeholder');
console.log(ip);
<input type="text" placeholder="some value" id="ip">
您可以使用 getAttribute()
方法获取 DOM 元素的属性值。 MDN - Element.getAttribute()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function myFunction() {
var x = document.getElementById("myText").placeholder;
console.log(x);
}
</script>
<html>
<body>
First Name: <input type="text" id="myText" placeholder="Name">
<p>Click the button to view the placeholder content in console.log</p>
<button onclick="myFunction()">Click Here</button>
</body>
</html>
如何在 javascript
中获取占位符的值我不想JQuery获取值
谁能告诉我如何获得它
const ip = document.getElementById("ip").getAttribute('placeholder');
console.log(ip);
<input type="text" placeholder="some value" id="ip">
您可以使用 getAttribute()
方法获取 DOM 元素的属性值。 MDN - Element.getAttribute()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function myFunction() {
var x = document.getElementById("myText").placeholder;
console.log(x);
}
</script>
<html>
<body>
First Name: <input type="text" id="myText" placeholder="Name">
<p>Click the button to view the placeholder content in console.log</p>
<button onclick="myFunction()">Click Here</button>
</body>
</html>