Javascript具有 textObject.defaultValue = somevalue ,用于检索输入的默认值(页面加载的存储值),即使您擦除输入并替换内容,您也可以仍然可以获得默认值。像这样:
Javascript has textObject.defaultValue=somevalue for retrieving the default value (stored value from page load) of an input even if you wipe the input and replace the contents, you can still get the default back. Like this:
// in the html page <input id="addr1" type="text" value="21 Oak St." /> // the jquery myInput = $("#addr1"); // the input, default value on page load = 21 Oak St. $(myInput).val('51 New St'); // wipe default and set new // alerts 21 Oak St alert($(myInput).val($(myInput)[0].defaultValue));如何在选择中完成此功能?
selectedIndex 是布尔值,不是值,所以不起作用。
selectedIndex is boolean, not the value, so that does not work.
谢谢!
推荐答案您可能想查看option元素的defaultSelected属性。
You probably want to look at the "defaultSelected" attribute of "option" elements.
最初,如果选项标签的原始HTML具有明确的selected属性,那么defaultSelected将为true。您可以通过在页面加载后使用Javascript设置选项标签上的属性来更改此选项,以响应您喜欢的任何条件。
Initially, "defaultSelected" will be true if the original HTML of the option tag had an explicit "selected" attribute. You can change that by setting the attribute on option tags with Javascript after the page has loaded, in response to whatever conditions you like.
更多推荐
"默认值"属性为< select>?
发布评论