Twilio客户端DTMF无法正常工作

I am working on a Twilio Client application and I am having a hard time sending DTMF tones. Here is the code I have so far:

<script type="text/javascript">
$.each(['0','1','2','3','4','5','6','7','8','9','star','pound'], function(index, value) { 
    $('#button' + value).click(function(){ 
        if(connection) {
            if (value=='star')
                connection.sendDigits('*')
            else if (value=='pound')
                connection.sendDigits('#')
            else
                connection.sendDigits(value)
            return false;
        } 
     });
  });
</script>


<div id="dialpad">
    <table>
    <tr>
    <td><input type="button" value="1" id="button1"></td>
    <td><input type="button" value="2" id="button2"></td>
    <td><input type="button" value="3" id="button3"></td>
    </tr>
    <tr>
    <td><input type="button" value="4" id="button4"></td>
    <td><input type="button" value="5" id="button5"></td>
    <td><input type="button" value="6" id="button6"></td>
    </tr>
    <tr>
    <td><input type="button" value="7" id="button7"></td>
    <td><input type="button" value="8" id="button8"></td>
    <td><input type="button" value="9" id="button9"></td>
    </tr>
    <tr>
    <td><input type="button" value="*" id="buttonstar"></td>
    <td><input type="button" value="0" id="button0"></td>
    <td><input type="button" value="#" id="buttonpound"></td>
    </tr>
    </table>
</div>

When I call my test number and press a button on the dialpad it does not send the values. Any help on this is greatly appreciated?

In your script block you need to have the connection object available. So above your function, you'll need something like:

var connection = null;
Twilio.Device.setup('your token');
params = { "number" : "5559871234", "outbound" : "true" };
connection = Twilio.Device.connect(params);

Essentially, this function just needs to "see" the connection variable. If your javascript files are in different places and you can't consolidate them, you can make the connection object global (not ideal) at least to see if you can get it working.

connection = null;

(without the "var" first)