JavaScript的“值"属性 [英] Javascript 'value' property

查看:75
本文介绍了JavaScript的“值"属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道哪些Javascript元素具有与之关联的值"属性?根据MDN,段落不具有值"属性,但具有"textContent"属性. 值"仅用于处理输入类型控件的文本内容吗?

I need to know which Javascript Elements have a "Value" property associated with them? According to MDN, paragraphs don't have "Value" property but have "textContent" property. Is "Value" only used for manipulating text content of input type controls?

推荐答案

value属性定义默认值,该默认值将在页面加载时显示在元素中.表单控件和其他一些html元素具有此属性(请参见下面的列表).

The value attribute defines a default value which will be displayed in the element on page load. Form controls and some other html elements have this attribute (see list below).

HTML中的value 属性和JavaScript中的value 属性有所不同.您可以使用value属性设置初始值,但是value属性包含控件的实际值. 来源

The value attribute in HTML and the value property in JavaScript work differently for these controls. You can set the initial value with the value attribute, but the value property contains the actual value of the control. Source

textContent属性设置或返回指定节点及其所有后代的文本内容.如果设置 textContent属性,则将删除所有子节点,并用包含指定字符串的单个Text节点替换.

The textContent property sets or returns the textual content of the specified node, and all its descendants. If you set the textContent property, any child nodes are removed and replaced by a single Text node containing the specified string.

要设置或返回元素的HTML内容,请改用innerHTML属性.

To set or return the HTML content of an element, use the innerHTML property instead.

在HTML DOM中,value属性设置或返回属性的值:

In HTML DOM, the value property sets or returns the value of the attribute:

  • 对于buttoninputoption元素,value属性指定该元素的初始值.
  • 对于li元素,value属性设置有序列表项的值.以下列表项将从该数字开始递增.
  • 对于progress元素,value属性指定已完成多少任务.
  • 对于param个元素,value属性指定一个元素的值.
  • For button, input and option elements, the value attribute specifies the initial value of the element.
  • For li elements, the value attribute sets the value of an ordered list item. The following list items will increment from that number.
  • For progress elements, the value attribute specifies how much of the task has been completed.
  • For param elements, the value attribute specifies the value of a element.

HTML元素:来源

  • button
  • input

    • button:键入="button"
    • checkbox:类型=复选框" <​​/li>
    • file:type =文件"
    • hidden:输入="hidden"
    • password:输入="password"
    • radio:输入="radio"
    • reset:type =重置"
    • submit:输入="submit"
    • text:输入="text"
    • button: type="button"
    • checkbox: type="checkbox"
    • file: type="file"
    • hidden: type="hidden"
    • password: type="password"
    • radio: type="radio"
    • reset: type="reset"
    • submit: type="submit"
    • text: type="text"

    这篇关于JavaScript的“值"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆