开发者

YUI getElementById('id').value deprecated?

开发者 https://www.devze.com 2023-01-01 08:38 出处:网络
My IDE complains the usage of value like in the below YUI statement is deprecated.. it wo开发者_运维问答rks, still, what is the proper usage.

My IDE complains the usage of value like in the below YUI statement is deprecated.. it wo开发者_运维问答rks, still, what is the proper usage.

  var idValue= document.getElementById('id').value;

thanks.. Babu


That's a perfectly valid statement, not sure what your IDE is having a problem with here. Various libraries have shortcuts for this (syntax shortcuts, not performance shortcuts), but none of that prevents the core JavaScript functionality from working, it's 100% valid.

I guess it's expecting the YUI style:

var element = new YAHOO.util.Element('id');
var idValue = element.get('value');

...but either method works, use whichever you want. I would prefer the shorter core javascript syntax here.


Babu,

As noted, the original code snippet does not use any JS library -- it sounds like the IDE is badly configured. Nick's answer looks good for YUI 2. In the newer YUI 3 syntax, you might do this:

YUI().use("node", function(Y) {
  var value = Y.one("#id").get("value);
});

-Eric

0

精彩评论

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