javascript - 将 jquery 添加到链接上

标签 javascript jquery variables

我在将 javascript 变量添加到链接末尾时遇到一些问题,这是我的代码

var locid = $.trim($(this > '.locid').text());

$(this).prepend('<a class="booknow2" href="../../availability/default.aspx?propid=' + locid + '"><span>Check availability &raquo;</span></a>');

如有任何帮助,我们将不胜感激

谢谢

杰米

最佳答案

要在已有另一个元素时获取直接子元素,请使用 .children() ,像这样:

var locid = $.trim($(this).children('.locid').text());

你不能真正使用$(this ...anything),你可以但是使用$(this).something(),并且 .something() 可以是 the tree traversal functions 中的任何一个四处走动。

关于javascript - 将 jquery 添加到链接上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3617027/

相关文章:

javascript - 如何在 Vuetify 文本输入字段中输入日期和时间

javascript - Ionic 2/3 类似于 WhatsApp 的信使功能

swift - 在 Swift 中,为什么分配给静态变量也会调用它的 getter

javascript - ID 中的空格并将变量放入 ID jquery

javascript - 单击容器但不单击容器中的元素时发生 jQuery/js 事件

Wordpress 中的 jQuery Roundabout CSS 位置问题

javascript - 提交时无法从 HTML 表单获取 jQuery 中的值

javascript - jQuery:JSON.stringify 保存在 cookie 后更改我的对象值

java:当前上下文中未知的变量?打开新的 JFrame 并调用子类时值(value)损失

java - 参数范围与局部变量范围?