日期:2014-05-16  浏览次数:20451 次

js取value值问题
<script>
function add01() {
var tableRow = document.getElementById('TabRow1');
var v = tableRow.firstChild.childNodes;
var len = v.length;

for(var i=0; i <= len; i++){
var values = document.getElementById("B01").value*document.getElementById("C01").value;
//if (values>0){
document.getElementById("D01").value = values;
//}
}
}
</script>
<table border='0' cellpadding='0' cellspacing='1' width='100%' id='TabRow1'>
<tr><td>
<input type="text" size="4" id="A01" name="A" value="">
<input type="text" size="8" id="B01" name="B" value="">
<input type="text" size="8" id="C01" name="C" value="" onKeyUp="add01();">

<input type="text" size="4" id="A01" name="A" value="">
<input type="text" size="8" id="B01" name="B" value="">
<input type="text" size="8" id="C01" name="C" value="" onKeyUp="add01();">
<td><tr></table>




<script>
function add02() {
var tableRow = document.getElementById('TabRow2');
var v = tableRow.firstChild.childNodes;
var len = v.length;

for(var i=0; i <= len; i++){
var values = document.getElementById("B02").value*document.getElementById("C02").value;
//if (values>0){
document.getElementById("D02").value = values;
//}
}
}
</script>
<table border='0' cellpadding='0' cellspacing='1' width='100%' id='TabRow2'>
<tr><td>
<input type="text" size="4" id="A02" name="A" value="">
<input type="text" size="8" id="B02" name="B" value="">
<input type="text" size="8" id="C02" name="C" value="" onKeyUp="add02();">

<input type="text" size="4" id="A02" name="A" value="">
<input type="text" size="8" id="B02" name="B" value="">
<input type="text" size="8" id="C02" name="C" value="" onKeyUp="add02();">
<td><tr></table>


怎么才能各取各的值

------解决方案--------------------
HTML code

<script>
function add(obj){
    var c = obj;
    var a, b, t;
    if(c.value=="" || isNaN(c.value)) return false;
    t = c;
    do{
        t = t.previousSibling;
        if(t.nodeType==1) if(t.tagName.toLowerCase()=="input"){
            b = t;
            break;
        }
    }while(true);
    do{
        t = t.previousSibling;
        if(t.nodeType==1) if(t.tagName.toLowerCase()=="input"){
            a = t;
            break;
        }
    }while(true);
    if(b.value=="" || isNaN(b.value)) return false;
    a.value = b.value * c.value;
}
</script>
<table border='0' cellpadding='0' cellspacing='1' width='100%' id='TabRow1'>
<tr><td>
    <input type="text" size="4" id="A01" name="A" value="">
    <input type="text" size="8" id="B01" name="B" value="">
    <input type="text" size="8" id="C01" name="C" value=&