【问题标题】:Can`t seem to make the selector select right似乎无法使选择器选择正确
【发布时间】:2012-03-13 19:35:57
【问题描述】:
<div class="form_div">
<form name="first" class="dirs" method="post" action="">

<table>
<tr>
  <td>
    <img src="path..." class="info">
    <div class="tip">
      <p>Some text</p>
    </div>
  </td>
</tr>
</table>

</form>
</div>

<script type="text/javascript">
$(document).ready(function() {
$(".info").tip({ effect : 'slide'});
});
</script>

我想从 div > form > table > tr > td 中选择带有类提示和 img 标签类信息的 div。但我无法使用脚本中的功能选择它。 选择器没有找到 img 标签和带有类提示的 div。 我是不是哪里出错了?

【问题讨论】:

  • 除了 jQuery .tip({}) 之外,您还使用哪些 javascript 库/插件@不是我听说过的功能。一旦你选择了你的图像/div,你想在元素上应用什么
  • @ManseUK Im trying to select the img tag first,and then when the mouse will be over the img tag the tip class will apear with the effect slide. @Simon West im 使用这个cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js

标签: javascript html selector


【解决方案1】:

使用这个:

$(".info, .tip")

它是multiple selector

看看.slideDown().slideUp().slideToggle()

【讨论】:

  • 我试过了,很有效,谢谢,还把脚本功能放在了页面的顶部。谢谢
  • @Nebunel 您不需要将脚本放在顶部,因为您使用的是.ready() 方法 - 这只会在 DOM 完成加载时执行代码
  • 算一算……唯一不正确的答案被接受了(并以某种奇怪的方式帮助了这个人……)。
  • 我试图再次放置在页面底部或中间,但它没有t select it,dont 知道为什么,我现在正在阅读更多关于 jquery 和 javascript 的文档,我想要找出问题是否是因为我有 4-5 个 elseif 语句,并且在每个 elseif 中具有相同的 img 标签和具有相同类的 div。
  • 对不起 ManseUK 我赶时间,我会探索其他答案,然后发布好的答案。我很抱歉。
【解决方案2】:

尝试将您的 javascript 代码放在正文的顶部

【讨论】:

  • 没有任何区别 - 它在 $(document).ready() 函数中
  • 成功了!谢谢你。我想知道,是因为我放置了 php 代码和多个 elseif,它们具有与 javascript 没有相同的类t know the first time to select? or i am mistaken? (Im new to javascript/jquery)
  • @Nebunel。简直不可能!!!您的代码已经在底部,并且在 DOM 就绪处理程序中。你确定?!
  • @gdoron 如果我将脚本代码放在页面底部它不会t select any of the classe, but if I place it on top it work for every elseif code of block that has the divs with the class and the img tag that i want to select. I want to know now why, im 很好奇
  • @Nebunel 你在哪里添加你正在使用的库????这需要在script 块之上...就是这样(使用.ready() 时)!
猜你喜欢
  • 2015-02-26
  • 1970-01-01
  • 2019-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
相关资源
最近更新 更多