什么是输入元素上的innerHTML? [英] What is innerHTML on input elements?

查看:17
本文介绍了什么是输入元素上的innerHTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想从 Wikipedia 上的 chrome 控制台执行此操作.我将光标放在搜索栏中,然后尝试执行 document.activeElement.innerHTML += "some text" 但它不起作用.我用谷歌搜索并查看了其他属性和属性,但无法弄清楚我做错了什么.

I'm just trying to do this from the chrome console on Wikipedia. I'm placing my cursor in the search bar and then trying to do document.activeElement.innerHTML += "some text" but it doesn't work. I googled around and looked at the other properties and attributes and couldn't figure out what I was doing wrong.

activeElement 选择器工作正常,它选择了正确的元素.

The activeElement selector works fine, it is selecting the correct element.

编辑:我刚刚发现它是 value 属性.所以我想改变我的要求.为什么改变innerHTML对输入元素起作用?如果我不能用它做任何事情,他们为什么要拥有该财产?

Edit: I just found that it's the value property. So I'd like to change what I'm asking. Why doesn't changing innerHTML work on input elements? Why do they have that property if I can't do anything with it?

推荐答案

设置 value 通常用于输入/表单元素.innerHTML 通常用于 div、span、td 和类似元素.

Setting the value is normally used for input/form elements. innerHTML is normally used for div, span, td and similar elements.

value 仅适用于具有 value 属性的对象(通常为表单控件).

value applies only to objects that have the value attribute (normally, form controls).

innerHtml 适用于每个可以包含 HTML 的对象(div、跨度,但还有许多其他和表单控件).

innerHtml applies to every object that can contain HTML (divs, spans, but many other and also form controls).

它们不是等效的或可替换的.取决于你想要达到的目标

They are not equivalent or replaceable. Depends on what you are trying to achieve

这篇关于什么是输入元素上的innerHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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