[英]Implementing Click Event Under Another Click Event in jQuery
This should be fairly easy but I can't get my head around it. 这应该很容易,但是我无法理解。 I have googled but can't find answers. 我已经用谷歌搜索,但是找不到答案。 I want to be able to capture some data when button A
is clicked and submit those data when button B
is clicked, via AJAX. 我希望能够在单击button A
时捕获一些数据,并在单击button B
时通过AJAX提交这些数据。
I have been thinking of this: 我一直在想:
$(document).on('click', 'button-a', function(){
var captureData = $('available-data').text();
$(document).on('click', 'button-b', function(){
submitData(captureData);
})
})
How can I achieve this? 我该如何实现?
Declare captureData
globally. 全局声明captureData
。 When you click on button-a the capture the value to captureData
and when you click on button-b then submit it. 当您单击按钮captureData
时,将捕获值捕获到captureData
并且当您单击按钮-b时,然后将其提交。 You should not include button b click event inside button-a click event. 您不应在button-a click事件中包含button b click事件。
var captureData = 'default value';
$(document).on('click', 'button-a', function(){
captureData = $('available-data').text();
});
$(document).on('click', 'button-b', function(){
submitData(captureData);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.