jQuery 在选定的类 div 中查找输入按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7187181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:30:59  来源:igfitidea点击:

Find input button within a selected class div

jquerybuttonjquery-ui-accordion

提问by user610983

How could I use jquery to find out this button within a div with class name "blueheaderbar accordionButton on" then change button value to "hide it"

我如何使用 jquery 在类名为“blueheaderbar AccordionButton on”的 div 中找出这个按钮,然后将按钮值更改为“隐藏它”

<div class="blueheaderbar accordionButton selected" style="margin-top:20px">
            <div class="floatleft">abc</div>
            <div class="floatright"><input class="showhidebtn" type="button" value="Show Outlet" style="margin:6px 16px 0 0; width:86px" /></div>
            <div class="clear"></div>
</div>

<div class="blueheaderbar accordionButton" style="margin-top:20px">
            <div class="floatleft">abc</div>
            <div class="floatright"><input class="showhidebtn" type="button" value="Show Outlet" style="margin:6px 16px 0 0; width:86px" /></div>
            <div class="clear"></div>
</div>

回答by shernshiou

I think the answer is:

我想答案是:

$("div.blueheaderbar.selected").find("input").val("hide it");

回答by RoToRa

"blueheaderbar accordionButton selected"isn't "a" single class name, but three. The CSS selector to select an element with all three classes is

"blueheaderbar accordionButton selected"不是“一个”单一的类名,而是三个。选择具有所有三个类的元素的 CSS 选择器是

.blueheaderbar.accordionButton.selected

(notice the lack of spaces!).

(注意缺少空格!)。

So to find an input inside there with jQuery is:

因此,要在其中使用 jQuery 查找输入是:

var $input = jQuery(".blueheaderbar.accordionButton.selected input");

or

或者

var $input = jQuery(".blueheaderbar.accordionButton.selected").find("input");

回答by Vivek

this will do the trick-

这将解决问题-

jQuery(".blueheaderbar.accordionButton.selected").find(".showhidebtn").hide();

and for secon div try this-

对于第二个 div 试试这个 -

jQuery(".blueheaderbar.accordionButton").find(".showhidebtn").hide();

you can try in this way also-

你也可以这样试试——

jQuery(".blueheaderbar.accordionButton.selected > .showhidebtn").hide();

Working Demo

工作演示

回答by Ben

This should change the text

这应该改变文本

$('.showhidebtn').click(function() {
  $(this).val('hide it');
});