开发者

replace or append text using jquery after loading the page?

I have string in the need to replace or append text after loading the page. please see the html code

<table cellpadding=2 cellspacing=0 width='100%' class='ms-informationbar'
    style='margin-bottom: 5px;' border=0>
   <tr>
    <td width=10 valign=center 
       style='padding: 4px'><img src='/_layouts/images/exclaim.gif' alt='' />
    </td>
    <td>Items on this list require content approval. Your submission will not
       appear in public views until approved by someone with proper rights. 
       <a href=javascript:HelpWindowKey("ContentApproval")>More information on 
       content approval.</a>
    </td>
   </tr>
 </table>
 <table cellpadding=2 cellspacing=0  
       width=100% class='ms-informationbar' style='margin-bottom: 5px;' border=0>
   </table>

Now I have to replace text

  Items on this list require content approval. Your submission will not
       appear in public views until approved by someone with proper rights. 
       <a href=javascript:HelpWindowKey("ContentApproval")>More information on 
       content approval.</a>** 

with

Items on this list require content approval. Your submission will not
  appear in public views until approved by someone with proper rights. 
  <a href=javascript:HelpWindowKey("ContentApproval")>More information on 
   content approval.</a> The editing session will timeout in 40 minu开发者_JAVA百科tes

How can we do this jQuery?


you could do this:

first, put a class or id in the TD element, so you can reference it more easily:

<td class="ApprovalNotice">Items on this list require content approval. Your submission will not
       appear in public views until approved by someone with proper rights. 
       <a href=javascript:HelpWindowKey("ContentApproval")>More information on 
       content approval.</a>
    </td>

Now you could do something like:

origHtml = $('.ApprovalNotice').html();
$('.ApprovalNotice').html(origHtml + yourText);

Or you could do something simpler:

<td class="ApprovalNotice">Items on this list require content approval. Your submission will not
           appear in public views until approved by someone with proper rights. 
           <a href=javascript:HelpWindowKey("ContentApproval")>More information on 
           content approval.</a><span class="timeout" style="display:none;">your text goes here</span>        </td>

and then

$('.timeout').show();


Add an ID to the TD you want to change.

<td id="infoText">...</td>

Then you can change the contents like this

$('#infoText').html('New Text')

http://jsfiddle.net/H5Vh8/


$(document).ready(function(){

$(".ms-informationbar tr td").eq(1).html('Items on this list require content approval. Your submission will not
  appear in public views until approved by someone with proper rights. 
  <a href=javascript:HelpWindowKey("ContentApproval")>More information on 
   content approval.</a> The editing session will timeout in 40 minutes');

});

This will select the second td which is found in a tr in an element with the class .ms-informationbar and replace its' content with the html between the quotes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜