遍历出来的class相同 所以我怎么才能每个button对应text框

 @{ List<ExaminationHerp.BookTable> users = (List<ExaminationHerp.BookTable>)ViewBag.Users;
                  foreach (ExaminationHerp.BookTable item in users)
                {
        <div class="rightmaintopleft">


          <div class="rightmaintopcontent"> <a href="#"><img src="@item.Img" border="0" style="float:left";"width:41px;height:64px" /></a>
            <div style="float:left; width:154px">
              <div class="wen1">@item.BookName
                <div>
                  <div class="wen2">出版社:@item.Press</div>
                  <div class="wen3">价格¥@item.Money(7.1折)</div>

                  <div class="wen4"><img src="~/BooxCssJsImg/img/che1.png" border="0"/> <a href="#">购买</a> | <img src="~/BooxCssJsImg/img/da.png"/><a href="#">数量:</a>  <input type="button" value="+" class="input2" style="width:20px"/ ">  <input  type="text" style="width:20px;margin-left:140px"; class="input1" value="0"/> <input  class="input3" type="button" value="-" style="width:20px"/>  </div>

                </div>
              </div>
            </div>
          </div>   
        </div>



遍历出来的 button 当点击+时 text的值+1 点击-时-1 遍历出来的class相同 所以我怎么才能每个button对应text框

和button对应的text框,应该同button在同一个父节点下。
可以用如下代码实现题目需求:

Btn.onclick = function() { 
    var children = this.parentElement.childNodes;
    var text;
    for(var i = 0; i < children.length; i ++) {
        if(children[i].nodeType === Node.TEXT_NODE) {
            text = children[i].nodeValue;
            break;
        }
    }
   alert(text); 
}

思路是得到button父节点下元素数组,循环遍历得到对应text框。

用心回答每个问题,如果对您有帮助,请采纳答案好吗,谢谢。

遍历出来的class是什么意思,题目不太懂

以我理解的说,我觉得你是说的那两个按钮点击之后text文本框的值不能改变,为Input设个class或id,为按钮添加onclick事件就可以了。如果我理解的有偏差,欢迎继续追问~~

如果你的button也在遍历里面的话
你button的class最好加上下循环的下标 这样容易区分

通过dom关系来操作就行了

 <div class="rightmaintopleft">
    <div class="rightmaintopcontent">
        <a href="#"><img src="@item.Img" border="0" style="float:left" ;"width:41px;height:64px" /></a>
        <div style="float:left; width:154px">
            <div class="wen1">
                @item.BookName
                <div>
                    <div class="wen2">出版社:@item.Press</div>
                    <div class="wen3">价格¥@item.Money(7.1折)</div>
                    <div class="wen4"><img src="~/BooxCssJsImg/img/che1.png" border="0" /> <a href="#">购买</a> | <img src="~/BooxCssJsImg/img/da.png" /><a href="#">数量:</a>  <input type="button" value="+" class="input2" style="width:20px" />  <input type="text" style="width:20px;margin-left:140px" ; class="input1" value="0" /> <input class="input3" type="button" value="-" style="width:20px" />  </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="rightmaintopleft">
    <div class="rightmaintopcontent">
        <a href="#"><img src="@item.Img" border="0" style="float:left" ;"width:41px;height:64px" /></a>
        <div style="float:left; width:154px">
            <div class="wen1">
                @item.BookName
                <div>
                    <div class="wen2">出版社:@item.Press</div>
                    <div class="wen3">价格¥@item.Money(7.1折)</div>
                    <div class="wen4"><img src="~/BooxCssJsImg/img/che1.png" border="0" /> <a href="#">购买</a> | <img src="~/BooxCssJsImg/img/da.png" /><a href="#">数量:</a>  <input type="button" value="+" class="input2" style="width:20px" />  <input type="text" style="width:20px;margin-left:140px" ; class="input1" value="0" /> <input class="input3" type="button" value="-" style="width:20px" />  </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.1.min.js"></script>
<script>
    $(':button').click(function () {
        var v = this.value, input = $(this)[v == '+' ? 'next' : 'prev'](), value = parseInt(input.val()) + (v == '+' ? 1 : -1);
        if (value < 0) value = 0;
        input.val(value)
    });
</script>

你button的加上id,取你的id里面get.text();