gpt4 book ai didi

javascript - 将变量传递给 JavaScript 函数

转载 作者:行者123 更新时间:2023-12-03 04:04:41 24 4
gpt4 key购买 nike

我写了一个Javascript函数

jQuery(document).ready( function newbie($) {

//var email = 'emailaddress'
var data = {
action: 'test_response',
post_var: email
};
// the_ajax_script.ajaxurl is a variable that will contain the url to the ajax processing file
$.post(the_ajax_script.ajaxurl, data, function(response) {
alert(response);
});
return false;
});

我将使用它来调用

newbie();

但是我想在调用该函数时传入一个变量(电子邮件地址),但我不知道如何执行此操作。那个 $ 符号似乎妨碍了我!非常感谢任何想法。

最佳答案

jQuery(document).ready(function(){
var email = 'emailaddress';
newbie(email);
});


function newbie(email) {
var data = {
action: 'test_response',
post_var: email
};
// the_ajax_script.ajaxurl is a variable that will contain the url to the ajax processing file
$.post(the_ajax_script.ajaxurl, data, function(response) {
alert(response);
});
return false;
}

 jQuery(document).ready(function(){
var newbie = function(email) {
var data = {
action: 'test_response',
post_var: email
};
// the_ajax_script.ajaxurl is a variable that will contain the url to the ajax processing file
$.post(the_ajax_script.ajaxurl, data, function(response) {
alert(response);
});
return false;
}

var email = 'emailaddress';
newbie(email);
});

关于javascript - 将变量传递给 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com