我有代码与AJAX / GET和代码重新加载数据从PHP文件i 有另一个块代码使用jquery现在我的问题为什么之后 当页面重新加载所有日期时,从mysql / php服务器重新加载数据 我无法使用其他脚本中的函数" functionToClick.js"。这个 文件有700行,工作很好,我使用没有AJAX的文件 只是普通的PHP代码。一些人想知道为什么会如此?
<head>
<title>Page Title</title>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="style.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styleTable.css">
</head>
<body>
<div id="contant"></div>
<h1></h1>
<div id="div_sum"></div>
<div id="div_list_value"></div>
<div id="div_list_choice"></div>
<div id="div_singels"></div>
<div id="div_singels_value"></div>
<p></p>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({ //create an ajax request to load_page.php
type: "GET",
url: "getBets.php",
dataType: "html", //expect html to be returned
success: function(response){
$("#contant").html(response);
/*here i need put my all SCRIPT
from another js file than its work
but its lang code ineed include here
how does i can this*/
}
});
});
</script>
<script src="functionToClick.js" type="text/javascript"></script>
</body>
$( document ).ready(function (){
var total = 1;
var value_team = [];
var sum_value = [];
var list_value = [];
var singels = [];
var singelsvalue = [];
//var test = 2;
$("td").on("click", function more()
{
var $this = $(this);
var choice = $this.attr("choice");
var value = $this.attr("value");
var index =
singels.indexOf($(this).attr("choice"));
var a = $this.attr("a");
var b = $this.attr("b");
var c = $this.attr("c");
var d = $this.attr("d");
var e = $this.attr("e");
var f = $this.attr("f");
var g = $this.attr("g");
var h = $this.attr("h");
var i = $this.attr("i");
var z = $this.attr("z");
var idBet = $this.attr("idBet");
var chaekA =
$this.next("td").attr("a");
var chaekB = $this.next("td").attr("b");
var chaekC = $this.next("td").attr("c");
var chaekAprev = $this.prev("td").attr("a");
var chaekBprev = $this.prev("td").attr("b");
var chaekCprev = $this.prev("td").attr("c");
var firstKidsa = $(this).parent().find("td:first").attr("a");
var lastKidsa = $(this).parent().find("td:last").attr("a");
var firstKidsb = $(this).parent().find("td:first").attr("b");
var lastKidsb = $(this).parent().find("td:last").attr("b");
var firstKidsc = $(this).parent().find("td:first").attr("c");
var lastKidsc = $(this).parent().find("td:last").attr("c");
var div_sum = $("#div_sum");
var div_list_value = $("#div_list_value");
var div_list_choice = $("#div_list_choice");
var div_singels = $("#div_singels");
var div_singels_value = $("#div_singels_value");
});
答案 0 :(得分:0)
$(document).ready(function() {
$.ajax({ //create an ajax request to load_page.php
type: "GET",
url: "getBets.php",
dataType: "html", //expect html to be returned
success: function(response){
$("#contant").html(response);
//alert(response);
$( ".with" ).click(function(){
$( this ).toggleClass( "with_click" );
//$( this ).siblings("th").removeClass( "with_click" );
});
$( document ).ready(function ()
{
var total = 1;
var value_team = [];
var sum_value = [];
var list_value = [];
var singels = [];
var singelsvalue = [];
//var test = 2;
$("td").on("click", function more()
{
var $this = $(this);
var choice = $this.attr("choice");
var value = $this.attr("value");
var index = singels.indexOf($(this).attr("choice"));
var a = $this.attr("a");
var b = $this.attr("b");
var c = $this.attr("c");
var d = $this.attr("d");
var e = $this.attr("e");
var f = $this.attr("f");
var g = $this.attr("g");
var h = $this.attr("h");
var i = $this.attr("i");
var z = $this.attr("z");
var idBet = $this.attr("idBet");
var chaekA = $this.next("td").attr("a");
var chaekB = $this.next("td").attr("b");
var chaekC = $this.next("td").attr("c");
var chaekAprev = $this.prev("td").attr("a");
var chaekBprev = $this.prev("td").attr("b");
var chaekCprev = $this.prev("td").attr("c");
var firstKidsa = $(this).parent().find("td:first").attr("a");
var lastKidsa = $(this).parent().find("td:last").attr("a");
var firstKidsb = $(this).parent().find("td:first").attr("b");
var lastKidsb = $(this).parent().find("td:last").attr("b");
var firstKidsc = $(this).parent().find("td:first").attr("c");
var lastKidsc = $(this).parent().find("td:last").attr("c");
var div_sum = $("#div_sum");
var div_list_value = $("#div_list_value");
var div_list_choice = $("#div_list_choice");
var div_singels = $("#div_singels");
var div_singels_value = $("#div_singels_value");
///////////////////////////////////////////// D
/* number 1*/ if(z==1&&a==0&&d==0&&e==0&&f==0)
{
sum_value.push(value);
list_value.push(value);
value_team.push(choice);
singels.push(choice);
singelsvalue.push(value);
total *= value;
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("a","1");
$this.attr("d","1");
$this.siblings("td").attr("d","1");
console.log("number 1 in D");
}
/* number 2*/ if(z=="x"&&b==0&&d==1)
{
singels.push(choice);
singelsvalue.push(value);
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("b","1");
console.log("number 2 in D");
}
/* number 3*/ if(z==2&&c==0&&d==1)
{
singels.push(choice);
singelsvalue.push(value);
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("c","1");
console.log("number 3 in D");
}
/* number 4*/ if(z==2&&c==1&&d==1)
{
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("c","0");
console.log("number 4 in D");
}
/* number 5*/ if(z=="x"&&b==1&&d==1)
{
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("b","0");
console.log("number 5 in D");
}
/* number 6*/ if(z==1&&a==1&&d==1)
{
if (singels.length >= 1)
{
list_value.shift(list_value.indexOf(+$(this).attr("value")), 1);
value_team.shift(value_team.indexOf(+$(this).attr("choice")), 1);
singels.shift(singels.indexOf($this.attr("choice")), 1);
singelsvalue.shift(singelsvalue.indexOf($this.attr("value")), 1);
console.log("yes" + singels.length)
}
total /= $(this).attr("value");
if (singels.length < 1)
{
list_value.pop(list_value.indexOf(+$(this).attr("value")), 1);
value_team.pop(value_team.indexOf(+$(this).attr("choice")), 1);
singels.pop(singels.indexOf($this.attr("choice")), 1);
singelsvalue.pop(singelsvalue.indexOf($this.attr("value")), 1);
console.log("yes 2")
}
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("a","0");
$this.attr("d","0");
$this.siblings("td").attr("d","0");
console.log("number 6 in D");
}
/////////////////////////////////////////////D sptziel*****************
/* number 7*/ if(z==1&&a==1&&d==1&&e==0&&chaekB==1&&lastKidsc==0)
{
list_value.splice(list_value.indexOf(+$(this).attr("value")), 1);
value_team.splice(value_team.indexOf(+$(this).attr("choice")), 1);
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
// total /= sum_value.splice(sum_value.indexOf(+$(this).attr("value")), 1);
sum_value.push($this.next("td").attr("value"));
list_value.push($this.next("td").attr("value"));
value_team.push($this.next("td").attr("choice"));
singels.push($this.next("td").attr("choice"));
singelsvalue.push($this.next("td").attr("value"));
total *= $this.next("td").attr("value");
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("a","0");
$this.attr("d","0");
$this.attr("e","1");
$this.siblings("td").attr("d","0");
$this.siblings("td").attr("e","1");
console.log("number 7 in D sptziel");
}
/* number 8*/ if(z==1&&a==1&&d==1&&e==0&&chaekB==0&&lastKidsc==1)
{
list_value.splice(list_value.indexOf(+$(this).attr("value")), 1);
value_team.splice(value_team.indexOf(+$(this).attr("choice")), 1);
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
// total /= sum_value.splice(sum_value.indexOf(+$(this).attr("value")), 1);
sum_value.push($(this).parent().find("td:last").attr("value"));
list_value.push($(this).parent().find("td:last").attr("value"));
value_team.push($(this).parent().find("td:last").attr("choice"));
singels.push($(this).parent().find("td:last").attr("choice"));
singelsvalue.push($(this).parent().find("td:last").attr("value"));
total *= $(this).parent().find("td:last").attr("value");
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("a","0");
$this.attr("d","0");
$this.attr("f","1");
$this.siblings("td").attr("d","0");
$this.siblings("td").attr("f","1");
console.log("number 8 in D sptziel");
}
/* number 9*/ if(z==1&&a==1&&d==1&&e==0&&chaekB==1&&lastKidsc==1)
{
list_value.splice(list_value.indexOf(+$(this).attr("value")), 1);
value_team.splice(value_team.indexOf(+$(this).attr("choice")), 1);
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
// total /= $(this).attr("value");
sum_value.push($(this).parent().find("td:last").attr("value"));
list_value.push($this.next("td").attr("value"));
value_team.push($this.next("td").attr("choice"));
singels.push($(this).parent().find("td:last").attr("choice"));
singelsvalue.push($(this).parent().find("td:last").attr("value"));
total *= $this.next("td").attr("value");
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("a","0");
$this.attr("d","0");
$this.attr("e","1");
$this.siblings("td").attr("d","0");
$this.siblings("td").attr("e","1");
console.log("number 9 in D sptziel");
}
/* number 10*/ if(z==2&&a==0&&e==1&&d==0&&chaekB==1&&firstKidsa==0)
{
list_value.splice(list_value.indexOf(+$(this).attr("value")), 1);
value_team.splice(value_team.indexOf(+$(this).attr("choice")), 1);
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
// total /= sum_value.splice(sum_value.indexOf(+$(this).attr("value")), 1);
/* sum_value.push($(this).parent().find("td:last").attr("value"));
list_value.push($this.prev("td").attr("value"));
value_team.push($this.prev("td").attr("choice"));
singels.push($(this).parent().find("td:last").attr("choice"));
singelsvalue.push($(this).parent().find("td:last").attr("value"));
*/
total *= $this.prev("td").attr("value");
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("c","0");
console.log("number 10 in D sptziel");
}
/* number 27*/ if(z==2&&c==1&&f==1&&d==0&&firstKidsa==0&&chaekBprev==1)
{
list_value.splice(list_value.indexOf(+$(this).attr("value")), 1);
value_team.splice(value_team.indexOf(+$(this).attr("choice")), 1);
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
total /= sum_value.splice(sum_value.indexOf(+$(this).attr("value")), 1);
sum_value.push($this.prev("td").attr("value"));
list_value.push($this.prev("td").attr("value"));
value_team.push($this.prev("td").attr("choice"));
// singels.push($this.prev("td").attr("choice"));
// singelsvalue.push($this.prev("td").attr("value"));
total *= $this.prev("td").attr("value");
div_sum.text("Total = " + total.toFixed(2));
div_list_value.html("Selected value = " + list_value.join(", "));
div_list_choice.html("Selected choice = " + value_team.join(", "));
div_singels.html("singels = " + singels.join(", "));
div_singels_value.html("singels_value = " + singelsvalue.join(", "));
$this.attr("c","0");
$this.attr("f","0");
$this.attr("e","1");
$this.siblings("td").attr("f","0");
$this.siblings("td").attr("e","1");
console.log("number 27 in F sptziel");
}
/* number 28*/ if(z==2&&c==1&&f==1&&d==0&&firstKidsa==1&&chaekBprev==1)
{
list_value.splice(list_value.indexOf(+$(this).attr("value")), 1);
value_team.splice(value_team.indexOf(+$(this).attr("choice")), 1);
singels.splice(singels.indexOf($this.attr("choice")), 1);
singelsvalue.splice(singelsvalue.indexOf($this.attr("value")), 1);
total /= sum_value.splice(sum_value.indexOf(+$(this).attr("value")), 1);
sum_value.push($this.prev("td").attr("value"));
list_value.push($this.prev("td").attr("value"));
value_team.push($this.prev("td").attr("choice"));
}
});
});
}
});
});