jquery从get调用中选择脚本节点

时间:2011-03-06 12:15:06

标签: jquery jquery-selectors

我想从ajax get调用中通过id选择一个脚本节点。

<script id="jqgrid_js" type="text/javascript">
...
</script>

来电:

            $.get(url, function(results){
              console.debug(results); //the jqgrid_js is included in the result
              console.debug($('#jqgrid_js')); //this returns the node from the actual page
              console.debug($('#jqgrid_js', results)); // in the result I can not select it
              var jqgrid_js = $('#jqgrid_js', results);
              //do the update
              $('#jqgrid_js').html(jqgrid_js); 
            }, "html");

我想知道为什么同一个select语句不返回节点,而节点肯定包含在“results”var中。

1 个答案:

答案 0 :(得分:0)

尝试转过来并使用find代替:

var jqgrid_js = $(results).find('#jqgrid_js');