可以使用jQuery从返回的字符串html中选择元素吗? [英] Can jQuery be used to select elements from a returned string html?

查看:100
本文介绍了可以使用jQuery从返回的字符串html中选择元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下jQuery代码:

For the following jQuery code:

$("#select").change(function() {
    $("#output").load("/output/", {}, function(data) {
        // I want to extract the value of an element in data
    }); 
});

data的内容是:

<div>
  Something
</div>
<input type="hidden" name="ajax-output" value="100" />

我想从data输出中获取值ajax-output.如何使用jQuery做到这一点?

I want to get the value ajax-output from the data output. How can I do that using jQuery?

推荐答案

要直接获取 ,由于它位于根目录,因此需要

To get it directly, since it's at the root, you need .filter(), like this:

$(data).filter("input[name='ajax-output']").val();

或者通过使用您自己插入的内容(通过 .load() 本身)获得它 .find() :

Or get it from the one you just inserted (via the .load() call itself) using .find():

$(this).find("input[name='ajax-output']").val();

这篇关于可以使用jQuery从返回的字符串html中选择元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆