jquery - 在 jQuery 函数内调用外部函数

标签 jquery

$(function () {
  $('#cmd').bind('keydown', function (evt) {
    if (evt.keyCode === 13) {


//* I want to call the function here *//
    }
    });

});

这是我想用参数调用的函数。

$(function (String msg) {

var cmdStr = msg;

    $.ajax({
        url: 'exec.php',
        dataType: 'text',
        data: {
            q: cmdStr
        },
        success: function (response) {
            $('#txtOut').append(response);
        }

    });

}
});

});

最佳答案

$('#cmd').keydown(
    function (event){
        if(event.keyCode == 13){
        event.preventDefault(); 
        /*you can call your function here*/
        $.ajax({
          url: "exec.php",
          method: "get",
          dataType: "text", 
          data: { q: $('#com').val()},
          success: function(data){ 
             $('#txtOut').append(response);
          }
        });
        /*still you can it here*/
      }
    }
);

关于jquery - 在 jQuery 函数内调用外部函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5701624/

相关文章:

jquery - 让两个div具有相同的高度

jquery - jQueryUI 安装是否有正确的目录结构?

javascript - 如何仅在精确的 div 内获得实时点击功能

jquery - 未捕获的类型错误 : Object #<Object> has no method 'validate'

jquery - 调整 Meteor 中文本区域的大小

javascript - 如何在javascript中提取特定字符之间的子字符串

javascript - 如何将本地文本文件上传到文本区域(网页内)

jquery - 在 jQuery 中使用动画旋转

php - 一个按钮有效,另一个按钮无效

javascript - JS 代码在 codepen 上运行缓慢,但在本地运行良好