日期:2014-05-17  浏览次数:20643 次

新手请教JS的一个事件对象问题。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
var fudu = null;
var fuhao = null;
$(function(){
fudu = parseFloat($("#moren").val());
$("#select").change(function(){
fudu = parseFloat($("#select").val());
});
$(".quanbu .jia,.quanbu .jian").click(function(){
fuhao = $(this).text();
changeVal();
// 如果是全部修改的就提交到 quanbu.php
$.post("/index.php?r=admin/odds/quanbu",{"jiajian":fuhao,"fudu":fudu});
});

$(".d_jia,.d_jian").click(function(){
fuhao = $(this).text();
var suoyin = $($(".all_cont").find("tr:gt(0)")).index($(this).parents("tr:first"));
switch(fuhao){
case "+":
$(this).siblings(".text").text(returnFloat2(parseFloat($(this).siblings(".text").text())+fudu));
break;
case "-":
$(this).siblings(".text").text(returnFloat2(parseFloat($(this).siblings(".text").text())-fudu));
break;
}
// 如果是单独修改就提交到 dandu.php
$.post("/index.php?r=admin/odds/dandu",{"jiajian":fuhao,"fudu":fudu,"suoyin":suoyin},function(data){alert(data)});
});


});
function changeVal(){
$(".all_cont").find("tr:gt(0)").each(function(){
switch(fuhao){
case "+":
$(this).find("td.num_c .text").text(returnFloat2(parseFloat($(this).find("td.num_c .text").text())+fudu));
break;
case "-":
$(this).find("td.num_c .text").text(returnFloat2(parseFloat($(this).find("td.num_c .text").text())-fudu));
break;
}
});
}

function returnFloat2(value) {
value = Math.round(parseFloat(value) * 100) / 100;
var xsd = value.toString().split(".");
if(xsd.length==1){
value = value.toString()+".00";
return value;
}
if(xsd.length>1){
if(xsd[1].length<2){
value = value.toString()+"0";  
}
return value;
}

</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="1" class="all_cont">
<tr>
<th width="100"><strong>序号</strong></th>
<th><strong class="quanbu"><span class="jia" style="cursor:pointer;">+</span> 利息 <span class="jian" style="cursor:pointer;">-</span></strong></th>
<th width="100"><strong>实际</strong></th>
<th><strong>自定义调节幅度</strong>
<select name="fudu" id="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
<option selected="selected" value="0.5" id="moren">默认</option>
</select>
</th>
</tr>
<tr>
<td align="center">1</td>
<td align="center" class="num_c"><span class="d_jia" style="cursor:pointer;">+</span> <span class="