从jQuery到Dojo - 如何在Dojo中获取无线电组选择的值

时间:2016-08-24 16:22:11

标签: javascript jquery dojo

我需要使用Dojo做一个项目,我完全混淆了如何处理一组无线电。考虑如下的示例,使用

很容易获得所选值
$('input[name=map]').on('change', function() {
    console.info($(this).val());
});

但是,请你知道如何做到这一点就是道场

require([ "dojo/dom",
          "dojo/on",
          "dojo/domReady!"], function(dom, on) {

   //------?

});



// jQuery way

$('input[name=map]').on('change', function() {
    console.info($(this).val());
});

// Dojo Way ???

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.11.2/dojo/dojo.js"></script>

<input type="radio" name="map" value="dark"> Dark<br>
<input type="radio" name="map" value="streets"> Street<br>
<input type="radio" name="map" value="terrain"> Terrain
&#13;
&#13;
&#13;

由于

1 个答案:

答案 0 :(得分:1)

您需要使用 // Dojo Way: require(["dojo/on", "dojo/query", "dojo/domReady!"], function(on, query) { query("[name='map']").map(function(radio){ on(radio, "change", function(evt){ console.log(this.value); }) }) });。这应该做到这一点。

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.11.2/dojo/dojo.js"></script>

<input type="radio" name="map" value="dark"> Dark<br>
<input type="radio" name="map" value="streets"> Street<br>
<input type="radio" name="map" value="terrain"> Terrain
&#13;
<?php
$servername = "";
$username = "";
$password = "";

$conn = new mysqli($servername, $username, $password);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?> 
&#13;
&#13;
&#13;