如何获取属性值的值?

时间:2017-10-03 10:24:40

标签: javascript

I want to show the value of the attribute as a parameter

https://jsfiddle.net/ufn6k25u/4/

1 个答案:

答案 0 :(得分:0)

我假设你想获得div元素的value属性。您可以使用Element.getAttribute()

来获取它



myFunction = function (event) {
    document.getElementById('hi').value = event.target.getAttribute('value');
}

<div onclick="myFunction(event)" value="50">
  click me
</div>

<input id="hi">
&#13;
&#13;
&#13;