jquery:单击时,将标题标记中的文本添加到输入框中

jquery:单击时,将标题标记中的文本添加到输入框中,jquery,Jquery,我有一本通讯录,还有一张靠近它的表格。。。对于表单,要求之一是填写消息的接收者。因此,当用户单击contactbook中的联系人时,titel标签中的用户名会自动出现在表单中的receiver input中 非常感谢您的帮助 几个额外的问题,1)标签是用户名还是有额外的文本 基本代码如下: jQuery(function() { jQuery('a.addTitleTag').click(function() { titleText = document.title; /

我有一本通讯录,还有一张靠近它的表格。。。对于表单,要求之一是填写消息的接收者。因此,当用户单击contactbook中的联系人时,titel标签中的用户名会自动出现在表单中的receiver input中

非常感谢您的帮助

几个额外的问题,1)标签是用户名还是有额外的文本

基本代码如下:

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);
    });
});

因此,在您的示例中,流程基本上如下所示:

  • 用户单击显示用户名的链接
  • 名为pmAmne(pmName?)的输入用“用户名”填充(标题属性单击链接的段落父项
  • 如果是这样,那么下面的代码应该起作用:

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

    我认为您想要的是使用username title属性获取p标记的“Firsname Lastname”部分

     $("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
     });
    
    $(“p[title='username'])。查找('a')。单击(函数{//Onclick)以查找p标记中的a
    contentOfP=$((p[title='username']).html();//获取p标记的内容,包括标记
    positionOfDash=contentOfP.indexOf('-');//我们需要破折号的位置来确定P标记的“Firstname Lastname”部分的结束位置
    names=contentOfP.substr(0,positionOfDash);//在不带破折号的情况下获取P标记的开头
    $(“输入[name='pmAmne']”).val(名称);//设置输入的值
    return false;//阻止链接的默认事件,使其不会在长页面上跳转到页面顶部
    });
    

    这应该会起作用的,斯图尔特·洛克斯顿的家伙不错!很管用。但这给我带来了另一个问题

    我准备好了:

        <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>
    
    
    (函数更新()
    {
    $.ajax(
    {
    键入:“GET”,
    url:“/doGet/pmKontakter.php”,
    超时时间:2000,
    成功:功能(数据)
    {
    $(“#pmKontakter”).html(数据);
    $(“#加载组件”).html(“”);
    设置超时(更新,10000);
    },
    错误:函数(XMLHttpRequest、textStatus、errorshown)
    {
    $(“#pmKontakter”).html('Din kontaktlista kunde inte hämtas för tilfället.');
    设置超时(更新,60000);
    }
    });
    })(jQuery);
    

    当我使用这段代码和你的代码时,你的代码不起作用。

    你如何实现他的代码,应该不会有冲突,尽管如此,当你的update()函数不需要任何参数时,为什么要用(jQuery)参数调用updae函数?