What is the best practice for parsing remote content with jQuery?

前端 未结 10 1620
时光说笑
时光说笑 2020-11-27 03:21

Following a jQuery ajax call to retrieve an entire XHTML document, what is the best way to select specific elements from the resulting string? Perhaps there is a library or

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 03:42

    If you wanted to find the value of specifically named fields (i.e. the inputs in a form) something like this would find them for you:

    var fields = ["firstname","surname", ...."foo"];
    
    function findFields(form, fields) {
      var form = $(form);
      fields.forEach(function(field) {
        var val = form.find("[name="+field+"]").val();
        ....
    

提交回复
热议问题