如何从一个按钮点击事件值到另一个按钮单击事件 [英] How to get values from a button click event to another button click event
本文介绍了如何从一个按钮点击事件值到另一个按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从按钮单击事件的div值,并在另一个按钮点击获取这些值event.But无法获取其他点击的事件时,这些价值观。
这里是我的div code:
'< DIV CLASS =dvDynamic_'+ PID +'><跨度类=count_'+ PID +'>' +数+'< / SPAN><跨度ID =PNAME的风格=保证金左:70像素;>' + PNAME +'< / SPAN><跨度ID =punitprice的风格=保证金左:150像素;>' + uprice +'< / SPAN>< / DIV>'
第一个按钮的点击事件code:
$(文件)。就绪(函数(){
VAR IDS = [];
$(#btnproceed)。点击(函数(){
调试器;
// $(DIV [^类='Apple苹果'])
$(DIV [^类='_ dvDynamic'])。每个(函数(){
调试器;
VAR的PID = $(本)的.text();
ids.push器(PID);
});
的id = [];
});
$ C $第二个按钮点击C:
$('#btnSubmit按钮')。点击(函数(){
调试器;
变种形式= [{
名:customerinfo
值:JSON.stringify($('#customerform'))
}];
VAR数据= JSON.stringify({
产品:身份证,
customerinfo:形式
});
$阿贾克斯({
键入:POST,
网址:@ Url.Action(
GetIds,
店),
数据:数据,
的contentType:应用/ JSON的;字符集= UTF-8,
成功:函数(R){
警报(r.d);
}
});
});
解决方案
现在您清楚阵列 IDS
每个执行 $(#btnproceed )。单击
处理程序
$(#btnproceed)。点击(函数(){
调试器;
// $(DIV [^类='Apple苹果'])
$(DIV [^类='_ dvDynamic'])。每个(函数(){
调试器;
VAR的PID = $(本)的.text();
ids.push器(PID);
});
的id = []; //在这里清楚previous每个环路中加入所有ID
});
只是删除这一行的id = [];
或移动这方法启动
$(#btnproceed)。点击(函数(){
的id = []; //在这里清楚previous处理程序添加的所有IDS
调试器;
// $(DIV [^类='Apple苹果'])
$(DIV [^类='_ dvDynamic'])。每个(函数(){
调试器;
VAR的PID = $(本)的.text();
ids.push器(PID);
});
//前方法退出 - ids数组包含previous环路中加入数据
});
I want to get values from a div on button click event and get those values in another button click event.But not able to fetch those values in other click's event. here is code of my div:
'<div class="dvDynamic_' + pid + '"><span class="count_' + pid + '">' + count + '</span><span id="pname" style = "margin-left:70px;">' + pname + '</span><span id="punitprice" style = "margin-left:150px;">' + uprice + '</span></div>'
Code of First Button click event:
$(document).ready(function () {
var ids = [];
$("#btnproceed").click(function () {
debugger;
// $("div[class^='apple-']")
$("div[class^='dvDynamic_']").each(function () {
debugger;
var pids = $(this).text();
ids.push(pids);
});
ids = [];
});
Code of Second button click :
$('#btnsubmit').click(function () {
debugger;
var form = [{
"name": "customerinfo",
"value": JSON.stringify($('#customerform'))
}];
var data = JSON.stringify({
'products': ids,
'customerinfo': form
});
$.ajax({
type: "POST",
url: "@Url.Action("
GetIds ", "
Store ")",
data: data,
contentType: "application/json; charset=utf-8",
success: function (r) {
alert(r.d);
}
});
});
解决方案
now you clear array ids
on each execute $("#btnproceed").click
handler
$("#btnproceed").click(function () {
debugger;
// $("div[class^='apple-']")
$("div[class^='dvDynamic_']").each(function () {
debugger;
var pids = $(this).text();
ids.push(pids);
});
ids = []; // here you clear all ids added in previous each loop
});
just remove this line ids = [];
or move this to method start
$("#btnproceed").click(function () {
ids = []; // here you clear all ids added in previous handler
debugger;
// $("div[class^='apple-']")
$("div[class^='dvDynamic_']").each(function () {
debugger;
var pids = $(this).text();
ids.push(pids);
});
//before method exit - ids array contain data added in previous loop
});
这篇关于如何从一个按钮点击事件值到另一个按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文