获得孩子和孙子的身份

时间:2016-01-14 08:11:51

标签: javascript jquery html css

public class Filter {

      public static void main(String[] args) throws IOException { 
           Automata automata = new Automata();
           if (automata.readUserInput()) {
                // BufferedReader in4 = new BufferedReader(new StringReader(automata.getInput())); or automata.input in case it is public
                // I don't understand why you want to read the input here again step by step
                // rather read the whole input here
                String userInput = automata.getInput();
           }
      }
 }
$(document).ready(function() {
  $("#save").click(function() {

    $("#div1").css({
      position: 'relative'
    });

    var a = $('#div1').children();
    a.each(function() {
      if ($(this).attr('id') == 'TextBoxesGroup') {
        var b = $(this).children().children();
        b.each(function() {
          continues($(this).attr('id'));
        });
      } else {
        continues($(this).attr('id'));
      }

    });

  });

});

var label = "";

function continues(id) {
  if (id != "") {
    //get label text
    if (id.substr(0, 5) == "label")

      label = $("#" + id).text();
    //alert("Get label id"+label+'181');

    var eid = id;
    //console.log("id"+eid);
    savePosition(eid, label);
  }
}

function savePosition(eid, label) { //console.log("#id"+"#" + eid);
  $("#" + eid).css({
    position: 'absolute'
  });
  var x = $("#" + eid).position();
  alert("name: " + eid + "Top position: " + x.top + " Left position: " + x.left + "label:" + label);

  continues();

}
#div1 {
  width: 610px;
  height: 330px;
  border: 1px solid #aaaaaa;
  background-color: white;
}

我的jQuery需要获取所有元素ID以保存其位置。但是,我一直收到这个错误:

  

未捕获的TypeError:无法读取未定义的属性“top”

我该怎么办? **我稍微修改了一下这个问题,因为有些部分链接到其他很难添加的部分

1 个答案:

答案 0 :(得分:0)

问题是因为data错了。

请尝试通过以下方式替换您的savePosition功能:

function savePosition(eid,label)
{
    $("#" + eid).css({position:'absolute'});
    var x = $("#" + eid).position();
    xTop = x.top;
    xLeft = x.left;
    $.ajax({
        type: "POST",
        url: "../../save.php",
        data: { name: eid,
                top: xTop,
                left: xLeft,
                txt: label
                },

        success:function(data) 
        {
                continues();
        }
    });
}