What is the output element? [closed]
Man, I don't get the output element at all.
Q: What is it?
The output element is just adding semantic meaning to the markup. It's harder to understand since we are used to the input element which browsers always render using some UI whereas the output element does not have any associated UI (as in a div element).
The onforminput event (as shown in one of the answers) has been deprecated and oninput event should be used instead:
<form oninput="result.value=a.valueAsNumber + b.valueAsNumber">
<input type="range" name="a"> +
<input type="number" name="b"> =
<output name="result"></output>
</form>
However, this is only a specific use case of the output tag and it's not necessary that javascript handles the result automatically. Any kind of output even if it's handled manually will suffice.
You would set an onforminput
event listener to it and then make calculations based on other input
tags within the same form
and set its value based on those calculations.
<input name="add_me" type="number"> +
<input name="me_too" type="number"> =
<output name="result" onforminput="value = add_me.valueAsNumber + me_too.valueAsNumber"></output>
Seems to me it's exactly what it says on the tin. It indicates the result of some calculation done somewhere else on your page.
精彩评论