开发者

dojo 1.5 select set not working

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="diji开发者_运维技巧t.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.


Your set call is rather off. The line you wrote would attempt to set an attribute called CA (which doesn't exist) to whatever the value of a variable named California is (which probably doesn't exist either).

What you really want to do is probably:

dijit.byId('selectv').set('value', 'CA');

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 is CA).

And yes, get and set are preferred over attr in 1.5 (attr will still work, but it's deprecated, and you'll see warnings if you have isDebug: true in djConfig.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜