English 中文(简体)
如果标有:无; Java
原标题:If P tag is display:none; Javascript

我有:

 $(document).ready(function() {
        $( p:contains("You") ).parent( span ).prev( input ).addClass( error );
  });

我的职司工作得很重,因为它增加了正确的投入,但是,如果载有你的段落所示,它只应增加这一类别。

是否有任何人想我如何能够这样做?


我每次投入的标记与此相似。

<li class="yourdetli">
    <label class="yourdet">House Number</label>
    <input type="text" id="ctl00_ContentPlaceHolder1_TB_HNumber2" name="ctl00$ContentPlaceHolder1$TB_HNumber2">
    <span style="color: Red; display: none;" class="errorp" id="ctl00_ContentPlaceHolder1_RequiredFieldValidator9">
        <p>You must complete this field</p>
    </span>
 </li>
最佳回答

You could use filter() and check the display property:

 $(document).ready(function() {
        $( p:contains("You") ).filter(function(){
                               return $(this).css( display ) ===  inline ;
                               })
                               .parent( span )
                               .prev( input )
                               .addClass( error );
  });

如果功能恢复真实,过滤器将保持该要素。

问题回答
$( p:contains("You"):visible )

假设你不改变文件任何地方的显示。

您不妨尝试收集所有<代码><p> tags, 其中载有<代码>you, 并抄送所有编号<>if的说明。

如cs,,inline 之后添加<代码>ror至input

这样做可能有助于

$(document).ready(function(){
  $("p:contains( you )").each(function(){
    if($(this).css( display ) ===  inline ){
      $(this).parent( span ).prev( :input ).addClass( error );
    }
  });
});

:contains is case sensitive. "You" Not sure if that is the problem.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签