我有一个联系簿和一个接近它的表单...对于表单,其中一个要求是填写消息的接收方。因此,当用户点击联系人中的联系人时,自动从titel-tag中的用户名应该在表单中出现在接收方中。jquery:单击时,将标题标签中的文本添加到输入框中
这一切的帮助表示赞赏!
我有一个联系簿和一个接近它的表单...对于表单,其中一个要求是填写消息的接收方。因此,当用户点击联系人中的联系人时,自动从titel-tag中的用户名应该在表单中出现在接收方中。jquery:单击时,将标题标签中的文本添加到输入框中
这一切的帮助表示赞赏!
所以基本上在你的榜样的过程是这样的:
如果是,则下面的代码应工作:
jQuery(function() {
jQuery('a.addTitleTag').click(function() {
titleText = jQuery(this).parents('p').attr('title');
jQuery("input[name='pmName']").val(titleText);
});
});
一些额外的问题,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);
});
});
我想你想要的是得到的用户名丝毫不差属性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
});
这应该做的伎俩
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工作。
你怎么实现他的代码,应该没有碰撞,但是,当你的update()函数不需要任何参数时,为什么要用(jQuery)参数调用updae函数呢? – 2009-01-02 16:57:30