标签: jquery-selectors

jQuery - 将表格单元格的文本值与单击元素放在同一行中

我单击表格单元格中的链接.我需要在同一个表行中获取特定单元格的值.

<tr>
    <td class="one">this</td>
    <td class="two">that</td>
    <td class="three">here</td>
    <td class="four"><a href="#">there</a></td>
</tr>
<tr>
    <td class="one">qwqw</td>
    <td class="two">dfgh</td>
    <td class="three">ui</td>
<td class="four"><a href="#">there</a></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

我有一个点击处理程序附加到第四个单元格中的链接.该单击处理程序调用一个打开模态窗口的函数.当提交模态中的表单时,我还想从链接被点击到该模态的行传递td class ="two"的值.

这是发送模态的函数(问题区域为var Something获取正确的值):

var Send = function() {
    var Name = $( '#name' ).val();
    var Something = $(this).closest('td').siblings('.two').text(); // version 1. doesn't work
    var Something = $(this).closest('tr').siblings('td.two').text(); // version 2 also doesn't work
    var Something = $(this).attr('class'); // version 3. just a test but also doesn't work
    $.ajax( {
        async: false,
        data: { name: Name, …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-selectors

48
推荐指数
3
解决办法
16万
查看次数

如何使用:not selector忽略多个类?

我在下面有这个选择器,它忽略任何lishow-all-boxes

$('.boxes li:not([class="show-all-boxes"]) input:checkbox')
Run Code Online (Sandbox Code Playgroud)

添加多个要被选择器忽略的类的最佳方法是什么?我认为这样做的一个例子可行,但事实并非如此:

$('.boxes li:not([class="show-all-boxes, show-all-circles, show-all-triangles"]) input:checkbox')
Run Code Online (Sandbox Code Playgroud)

jquery jquery-selectors

48
推荐指数
2
解决办法
3万
查看次数

jquery查找与上下文选择

拥有以下html代码段

<div class="something">
    <p>Some text</p>
</div>
<div class="somethingElse">
    <p>some other text</p>
</div>
Run Code Online (Sandbox Code Playgroud)

我认为以下jquery片段是相同的(将具有相同的结果):

$(".something").find("p").css("border", "1px solid red");

$("p", ".something").css("border", "1px solid red");
Run Code Online (Sandbox Code Playgroud)

我的问题是,一个片段是否优于另一个片段并且应该被使用

jquery jquery-selectors

47
推荐指数
4
解决办法
1万
查看次数

父窗口中的jQuery select元素

有没有办法使用jQuery在父窗口中选择DIV?

例如:

主页包含这个,

<div id="testdiv"></div>
Run Code Online (Sandbox Code Playgroud)

弹出页面有一个带有一些选项和"应用"按钮的表单.当用户单击"应用"时,它会影响主页面上的样式属性.

沿着逻辑的东西,

parent.$("#testdiv").attr("style", content from form);
Run Code Online (Sandbox Code Playgroud)

jquery popup parent jquery-selectors

47
推荐指数
2
解决办法
11万
查看次数

什么是jQuery选择器中的"上下文"?

两者之间有什么区别吗?

$('input.current_title', '#storePreferences').prop('disabled', false);
Run Code Online (Sandbox Code Playgroud)

$('#storePreferences input.current_title').prop('disabled', false);
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-selectors

47
推荐指数
2
解决办法
5万
查看次数

How do I select the next "n" elements starting from the current element in jQuery?

How do I select the next "n" elements starting from the current element? What I mean is...

 $(this).attr(...);
Run Code Online (Sandbox Code Playgroud)

I want to do this "n" times. For the example of n=4:

$(this).attr(...);
$(this).next().attr(...);
$(this).next().next().attr(...);
$(this).next().next().next().attr(...);
Run Code Online (Sandbox Code Playgroud)

or perhaps do it in a loop:

for (i = 0; i < n; i++) {
    $(this).next().attr(...);
}
Run Code Online (Sandbox Code Playgroud)

How can I do this? Is there a way I can do this by selecting the next "n" elements or in a loop?

jquery jquery-selectors

46
推荐指数
2
解决办法
1万
查看次数

jQuery UI选项卡.如何根据不基于索引的id选择选项卡

我有两个选项卡并配置了jQuery UI.

ul  class="tabs"
  li  tabone
  li tabtwo
ul
Run Code Online (Sandbox Code Playgroud)

动态地从C#代码后面我将隐藏或选择一些选项卡让我们说tabtwo,另一个选项卡必须隐藏或不显示.我可以使用JavaScript在JavaScript中执行此操作.tabs({selected:1});,.tabs(disable:0).但我不想使用选项卡索引来执行此操作.

是否有任何备用选项根据其名称/ ID选择?

jquery jquery-ui jquery-plugins jquery-selectors

46
推荐指数
3
解决办法
13万
查看次数

jQuery - a:not()中的多个选择器?

我似乎无法得到以下工作:

$('input:not([type=radio][type=checkbox])').live('click', function() {
    alert("You haven't clicked a radio or checkbox!");
});
Run Code Online (Sandbox Code Playgroud)

尝试了一些不同的语法,任何人都可以帮我解决这个问题.

干杯
查理

jquery jquery-selectors

46
推荐指数
2
解决办法
3万
查看次数

不区分大小写的jQuery属性选择器

我正在使用属性包含选择器$('[attribute*= value]')执行以下操作

<input name="man-news">
<input name="milkMan">

<script>    
    $( "input[name*='man']").css("background-color:black");
</script>
Run Code Online (Sandbox Code Playgroud)

这适用于第一个输入而不是第二个输入,因为" Man "具有大写" M "

如何制作$( "input[name*='man']")不区分大小写的选择器?

javascript jquery jquery-selectors

46
推荐指数
2
解决办法
3万
查看次数

获取元素的jQuery选择器

在伪代码中,这就是我想要的.

var selector = $(this).cssSelectorAsString(); // Made up method...
// selector is now something like: "html>body>ul>li>img[3]"
var element = $(selector);
Run Code Online (Sandbox Code Playgroud)

原因是我需要将其传递给外部环境,其中字符串是我交换数据的唯一方式.然后,此外部环境需要发回结果以及要更新的元素.所以我需要能够为页面上的每个元素序列化一个唯一的CSS选择器.

我注意到jquery有一个selector方法,但它似乎不适用于此上下文.它仅在使用选择器创建对象时才有效.如果使用HTML节点对象创建对象,则它不起作用.

javascript jquery jquery-selectors

45
推荐指数
5
解决办法
3万
查看次数