关于jquery的live()的小问题

发布于 2024-09-16 21:41:06 字数 319 浏览 1 评论 0原文

我将如何更改标签的 html,如下所示:

$('#someId').html('

foo bar

');

在使用 live() 或 delegate() 函数时?只是为了澄清,我不希望这种情况发生在悬停、焦点或单击时...我只是希望 jquery 立即更改某个标签内的 html。

基本上,我试图更改 Mojomotor 的小下拉面板中的徽标,并且我不想每次升级到新版本时都更改徽标。

有什么建议吗?

How would I change the html of a tag like so:

$('#someId').html('<p>foo bar</p>');

while using the live() or delegate() function? Just for clarification I don't want this to happen on hover or focus or click... I just want jquery to immediately change the html inside of a certain tag.

Basically, I'm trying to change the logo in the Mojomotor's little dropdown panel and I don't want to change the logo every time I upgrade to a new version.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热鲨 2024-09-23 21:41:06

.live().delegate() 不是这样工作的,你所追求的仍然是通过 .livequery() 插件 或直接在 文档中。准备好(如果页面加载时出现),如下所示:

$(function() {
  $('#someId').html('<p>foo bar</p>');
});

或者使用 .livequery( ) 如果在页面中动态替换:

$('#someId').livequery(function() {
  $(this).html('<p>foo bar</p>');
});

.live()< /code>.delegate() 工作事件冒泡...刚刚出现的元素不会执行此操作,而 clickchange 等会执行此操作。

.live() and .delegate() don't work like this, what you're after is still done through the .livequery() plugin or simply in the document.ready if it's present on page load, like this:

$(function() {
  $('#someId').html('<p>foo bar</p>');
});

Or with .livequery() if it's replaced dynamically in the page:

$('#someId').livequery(function() {
  $(this).html('<p>foo bar</p>');
});

.live() and .delegate() work off of event bubbling...an element just appearing doesn't do this whereas a click or change, etc would.

短暂陪伴 2024-09-23 21:41:06

只需在 DOM 加载时执行即可。

<script type="text/javascript">
    $(document).ready(function() {
        $('#someId').html('<p>foo bar</p>'); 
    });
</script>

Just do it when the DOM loads.

<script type="text/javascript">
    $(document).ready(function() {
        $('#someId').html('<p>foo bar</p>'); 
    });
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文