What is the default value of a (input type=) submit button

梦想与她 提交于 2019-12-17 20:53:00

问题


I am building a multilingual website and I was wondering how is set the default value of a submit button? Is it something browser specific or does it rely on the system language or both? ie : I'm just asking if I've to set a specific value according to the language of the page or if it will be done automatically? I've been unable to find anything about that in the w3c specs. Thanks!


回答1:


The HTML 4.01 specification is rather vague about this, but the HTML5 CR is more explicit. It says, in the description of <input type=submit>: “If the element has a value attribute, the button's label must be the value of that attribute; otherwise, it must be an implementation-defined string that means "Submit" or some such.” This does not specify that the string should be language-dependent in any sense, but in practice it usually depends on the language of the browser.

The conclusion that you should always set the value attribute, to make sure it is in the language of the page and, moreover, that it is informative. Quite often, a generic name that means “submit” is too abstract.

On the technical side, the value of a submit button is undefined if there is no value attribute. This means that the getAttribute() method yields null and the value property of the element node is the empty string. However, on form submission, browsers in practice act as if the value were the string that they use as button label.




回答2:


If a value is missing, the browser will place it there (in the language that the browser is in).

So assuming you don't know the language of the browser, it's best to just set the value attribute yourself.

Also, it's more consistent to have a translation for every text used in the website (which includes buttons).



来源:https://stackoverflow.com/questions/23592777/what-is-the-default-value-of-a-input-type-submit-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!