0

I set a variable 'api_key' on document load. I want to modify this variable with the text of an input field after clicking a button

var api_key = "";

//my button has an id named "btn-verify", the input field has an id named "verify"
$("#btn-verify").click({
        api_key = $("#verify").val();

    });

this doesn't work, how should I fix this. How do I assign api_key to the value of the input field, on click of a button

4

2 回答 2

2

绑定处理程序时缺少函数声明。

改变

$("#btn-verify").click({

//Missing function declaration--v   
  $("#btn-verify").click(function (){
于 2013-05-02T20:44:12.113 回答
0

尝试这个:

$(document).ready(function(){
    $("#btn-verify").click(function(){
        api_key = $("#verify").val();
    });
});

ready 函数将导致 JS 在运行前等待 DOM 完成加载。

于 2013-05-02T20:48:52.587 回答