简体   繁体   English

如何确定是否已选中DOJO复选框?

[英]How to determine whether a DOJO Checkbox is checked or not?

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

在我的javaScript函数中,如何检查上方dojo复选框是否已选中。

You can check this in various ways. 您可以通过多种方式进行检查。 You can use plain HTML/DOM/JavaScript and use something like: 您可以使用纯HTML / DOM / JavaScript并使用类似以下内容:

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

or with Dojo: 或使用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: 这就是@Shreyos Adikari的意思,但您也可以将窗口小部件本身(在屏幕后面执行相同的操作)与:

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. 前两种方法与后一种方法的区别在于,前两种使用DOM节点,而后一种使用具有相似属性的Dojo CheckBox小部件/对象。 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 . 但是无论如何,网络上有很多有关如何实现此目的的示例(甚至在Dojo文档本身中),我建议您查看API文档或至少查看示例

You can use javascript function checked over id, like: 您可以使用通过id检查的javascript函数,例如:

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

Here .checked will return "1" in case the checkbox is checked. 如果选中此复选框,则.checked将返回“ 1”。
Please try this in your javascript and let me know in case of any concern. 请在您的JavaScript中尝试此操作,如有任何疑问,请通知我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM