最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to determine whether a DOJO Checkbox is checked or not? - Stack Overflow

programmeradmin2浏览0评论
<input id="test" type="checkbox" value="test" data-dojo-type="dijit.form.CheckBox">

How to check above dojo checkbox is checked or not in my javaScript function.

<input id="test" type="checkbox" value="test" data-dojo-type="dijit.form.CheckBox">

How to check above dojo checkbox is checked or not in my javaScript function.

Share Improve this question edited Jun 19, 2013 at 3:54 Shreyos Adikari 12.7k19 gold badges75 silver badges82 bronze badges asked Apr 5, 2013 at 9:42 user1727939user1727939
Add a comment  | 

2 Answers 2

Reset to default 13

You can check this in various ways. You can use plain HTML/DOM/JavaScript and use something like:

if (document.getElementById("test").checked) { ... }

or with Dojo:

if (dojo.byId("test").checked) { ... }

This is what @Shreyos Adikari meant I think but you can also use the widget itself (which is doing the same thing behind the screens) with:

if (dijit.byId("test").checked) { ... }

The difference between the first two methods and the last one, is that the first two use DOM nodes, while the last one uses the Dojo CheckBox widget/object which has a similar property. I personally recommend the last one, because this should always work, even if they decide to change their template.

But anyhow, there are plenty of examples on the web about how to achieve this (even on the Dojo documentation itself), I recommend you to view the API Documentation or at least the examples.

You can use javascript function checked over id, like:

 if (test.checked == 1){
          alert("checked") ;
    }
else{
          alert("unchecked") ;
    }

Here .checked will return "1" in case the checkbox is checked.
Please try this in your javascript and let me know in case of any concern.

发布评论

评论列表(0)

  1. 暂无评论