如何在字符串中使用jQuery?

编程入门 行业动态 更新时间:2024-10-25 18:35:53
本文介绍了如何在字符串中使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用jquery,如何搜索一串html代码,例如:

Using jquery, how can you search through a string of html code, for example:

<script type="text/javascript"> alert($('#t','<span id="t">d</span>').html()); </script>

我希望在警报中得到d,但是我没有得到定义...

I expect to get d in the alert, but I get undefined...

有人知道该怎么做吗?

实际上,我使用ajax请求来获取页面的html字符串.如果我然后尝试将字符串粘贴到某个标签中,那么当前页面将变得一团糟.所以我想搜索给定的字符串.

Actually I use an ajax request to get an html string of the page. If I then try to paste the string in some tag, then the current page gets all messed up. So I wanted to search through the given string.

推荐答案

context 参数是jQuery将在 in 内搜索的上下文. IE.它将查看该上下文的子元素,而不是上下文本身.这有效:

The context parameter is the context within which jQuery will search. I.e. it will look at child elements of that context but not at the context itself. This works:

alert($('#t','<span><span id="t">d</span></span>').html());

我不太确定您正在尝试做什么.您已经有了该元素,无需搜索.此示例可能永远不会应用于任何现实问题.

I'm not quite sure what you're trying to do there though. You already have the element, no need to search for it. This example will probably never be applied to any real world problem.

更多推荐

如何在字符串中使用jQuery?

本文发布于:2023-10-27 02:52:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   如何在   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!