dojo 1.5 选择集不工作
您好,我想在我的应用程序中使用选择按钮。所以我正在尝试一个简单的选择示例。我尝试了很多不同的选择。我无法成功设置选择按钮的值。请仔细阅读以下代码并纠正我。
<脚本类型=“text/javascript”> dojo.require("dojo.parser"); dojo.require("dijit.form.Select"); dojo.addOnLoad(函数(){ dijit.byId('selectv').set('CA',加利福尼亚州); }); <选择名称=“selectv”dojoType=“dijit.form.Select”> <选项值=“TN”> 田纳西州 <选项值=“VA”> 弗吉尼亚州 <选项值=“WA”> 华盛顿 <选项值=“FL”> 佛罗里达 <选项值=“CA”> 加利福尼亚州
我想使用 set 方法设置选择框的值。我在 1.5 之前的 attr 中看到了不同的选项,但它不起作用。请让我知道错误。提前致谢。
HI, I want to use select button in my application. So I am trying with a simple select example. I have a tried alot with different options. I could not succeed in setting the value of select button. Please gothrough the following code and correct me.
<script type="text/javascript"> dojo.require("dojo.parser"); dojo.require("dijit.form.Select"); dojo.addOnLoad(function(){ dijit.byId('selectv').set('CA',California); }); </script> <select name="selectv" dojoType="dijit.form.Select"> <option value="TN"> Tennessee </option> <option value="VA"> Virginia </option> <option value="WA"> Washington </option> <option value="FL"> Florida </option> <option value="CA"> California </option> </select>
I would like to set the value of select box using set method. I have seen different options with attr pre-1.5, but it didnt work. Please let me know the mistake. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
set
电话相当关闭。您编写的行将尝试将名为CA
的属性(该属性不存在)设置为名为California
的变量的值(可能不存在)任何一个)。您真正想要做的可能是:
这会将 Select 小部件的 value 属性设置为字符串
CA
,这将导致选择 California 选项(因为其值为CA< /代码>)。
是的,在 1.5 中,
get
和set
优于attr
(attr
仍然有效,但已被弃用,如果djConfig
中有isDebug: true
,您将会看到警告。)Your
set
call is rather off. The line you wrote would attempt to set an attribute calledCA
(which doesn't exist) to whatever the value of a variable namedCalifornia
is (which probably doesn't exist either).What you really want to do is probably:
Which would set the value attribute of your Select widget to the string
CA
, which would result in the California option being selected (as its value isCA
).And yes,
get
andset
are preferred overattr
in 1.5 (attr
will still work, but it's deprecated, and you'll see warnings if you haveisDebug: true
indjConfig
.)