2009-01-02 101 views

回答

2

所以基本上在你的榜樣的過程是這樣的:

  1. 用戶點擊與名pmAmne 的鏈接說用戶名
  2. 輸入(pmName? )得到充滿'用戶名'(標題屬性的段落父母點擊?

如果是,則下面的代碼應工作:

jQuery(function() { 
    jQuery('a.addTitleTag').click(function() { 
     titleText = jQuery(this).parents('p').attr('title'); 
     jQuery("input[name='pmName']").val(titleText); 
    }); 
}); 
1

一些額外的問題,1)<title>標籤只是用戶名或它是否有額外的文本。

基地下面的代碼:

jQuery(function() { 
    jQuery('a.addTitleTag').click(function() { 
     titleText = document.title; // Placed in new var incase of extra manipulation needed. 
     jQuery("input[name='username']").val(titleText); 
    }); 
}); 
0

我想你想要的是得到的用戶名絲毫不差屬性p標籤的「Firsname姓氏」的一部分。

$("p[title='username']").find('a').click(function{ //Onclick for the a in the p tag 
    contentOfP = $("p[title='username']").html(); //get the content of the p tag, including the <a> tag 
    positionOfDash = contentOfP.indexOf('-'); //We need the position of the dash to determine where the 'Firstname Lastname' part of the P tag ends 
    names = contentOfP.substr(0, positionOfDash); //Get the start of the P tag withouth the dash 
    $("input[name='pmAmne']").val(names); //Set the value of the input 
    return false; //Block the default event for the link so it doesn't jump to the top of the page on long pages 
}); 

這應該做的伎倆

0

stuartloxton傢伙真好!作品篦。但它爲我造成了問題。

我媒體鏈接有:

<script type="text/javascript"> 
(function update() 
    { 
     $.ajax(
     { 
     type: 'GET', 
     url: '/doGet/pmKontakter.php', 
     timeout: 2000, 

      success: function(data) 
      { 
       $("#pmKontakter").html(data); 
       $("#loadingComponent").html(''); 
       window.setTimeout(update, 10000); 
      }, 

      error: function (XMLHttpRequest, textStatus, errorThrown) 
      { 
       $("#pmKontakter").html('<h3>Din kontaktlista kunde inte hämtas för tillfället.</h3>'); 
       window.setTimeout(update, 60000); 
      } 
     }); 
    })(jQuery); 
</script> 

當我使用此代碼abow和你的代碼,你的代碼dosent工作。

+0

你怎麼實現他的代碼,應該沒有碰撞,但是,當你的update()函數不需要任何參數時,爲什麼要用(jQuery)參數調用updae函數呢? – 2009-01-02 16:57:30

相關問題