"默认值"属性为< select>?

编程入门 行业动态 更新时间:2024-10-24 18:24:54
本文介绍了"默认值"属性为< select>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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.

更多推荐

&QUOT;默认值&QUOT;属性为&lt; select&gt;?

本文发布于:2023-11-17 03:17:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608621.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:默认值   属性   QUOT   amp   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!