欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Jquery获取某行某列的值 jQueryAjaxHTMLCache

程序员文章站 2022-07-12 17:27:38
...
function getRow(this) {       
  var row = $(this).parent("td").parent("tr");   //获取列表的row(行)
  var value=$("#cellid",row).html();    //cellid是列名的ID   
}




function onloadMessage()
{
    $.ajax({
    type:'post',
    url:'ShowBook',
    cache:false,
    async:true,
    success:function(transport)
     {
    
        var de=transport.documentElement;
        var nodelist = de.getElementsByTagName("BookList");
        var htmlstr="";

        for (var i = 0; i < nodelist.length; i++) {
       
         var bookid=nodelist[i].getElementsByTagName("bookid")[0].text;
         var bookname=nodelist[i].getElementsByTagName("bookname")[0].text;
         var author=nodelist[i].getElementsByTagName("author")[0].text;
         var time=nodelist[i].getElementsByTagName("time")[0].text;
         var price=nodelist[i].getElementsByTagName("price")[0].text;
         htmlstr+="<tr>"
         +"<td id='bookid'>"
         +bookid
         +"</td>"
         +"<td>"
         +bookname
         +"</td>"
         +"<td>"
         +author
         +"</td>"
         +"<td>"
         +time
         +"</td>"
         +"<td id='oldprice'>"
         +price
         +"</td>"
         +"<td>"
        htmlstr+="<input type='button' value='修改单价' id='edit' onclick='editprice(this)'><td>"
        htmlstr+="</tr>"
        
       }
       $("#bookList").html(htmlstr);
     }
    });
}


function editprice(obj)
{
  var row=getRow(obj);
  var oldprice=$("#oldprice",row).html();
  var bookid=("#bookid",row).html();
  $("#oldprice",row).html("<input type='text' id='newprice' size='7'>");
  $("#newprice",row).blur(function(){
    var newprice=$("#newprice",row).val();
    if(newprice=="" || newprice==null)
    {
         newprice=oldprice;
    }
   
    if(isNaN(newprice))                           //判断输入价格的格式是否正确
       {
        alert("请输入数字");
        $("#newprice").focus();                      //文本重新获取光标
        $("#newprice").val("");
        return false;
       }
      alert(newprice);
     onloadMessage();
  });
}


function getRow(obj)
{

  var row=$(obj).parent("td").parent("tr");
  return row;
}