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

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

问题描述

我只是想从维基百科的镀铬控制台这样做。我将光标放在搜索栏中,然后尝试执行 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 selector工作正常,它正在选择正确的元素。

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

编辑:我刚刚发现这是属性。所以我想改变我所要求的。为什么改变 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?

推荐答案

设置通常用于输入/表单元素。 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 applies only to objects that have the value attribute (normally, form controls).

innerHtml 适用于可以包含 HTML (divs,span,but many other and also form controls)的每个对象。

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天全站免登陆