【发布时间】:2018-12-18 17:28:52
【问题描述】:
我很确定这个问题的答案是否定的,但是,
有没有办法像这样编写 HTML 元素:
<button innerText="This is the button text" />
<!-- INSTEAD OF LIKE THIS: -->
<button>This is the button text</button>
对于这样的示例,我的请求似乎很笨拙,但是当您通过 ReactJS 返回多个看起来像这样的元素时,它更有意义。
<button
className="btn"
somePropA="Some Value"
somePropB="Some Value"
somePropC="Some Value"
title="Some title"
>
Some button innerText
</button>
<!-- VERSUS: -->
<button
className="btn"
somePropA="Some Value"
somePropB="Some Value"
somePropC="Some Value"
title="Some title"
innerText="Some button innerText"
/>
我希望能够为button、span 等做到这一点。
【问题讨论】:
-
以后可以用JS添加属性值。使用按钮
<input type="button" value="Button text">将完全满足您的需求。 -
谢谢@Teemu。我考虑过这一点,但出于几个原因,我不想依赖客户端 JavaScript 来使元素工作。我正在使用 React 并考虑编写一些代码来进行替换,如果没有本地方法来实现这一点。
标签: javascript html reactjs dom