【问题标题】:jquery getting dynamically generated content from title attributejquery从title属性获取动态生成的内容
【发布时间】:2012-06-10 18:38:41
【问题描述】:

我有一个 html 表 <table>,其中每列的列数都有标题属性,该属性是通过 ajax() 函数动态生成的。我正在尝试从表格的所有列中获取内容,但标题属性的内容没有显示出来,

例如:

<table>
   <tr>
       <td id="myid" title="some data generated by ajax() call"> test </td>
   </tr>
  </table>

jQuery 代码:

 $(document).ready(
     function(){
        alert($("td#myid").html());


});    

【问题讨论】:

  • 如果没有其他代码,我真的不能说,但也许可以在 Ajax 调用完成后尝试放置?

标签: javascript jquery title


【解决方案1】:

在你的 ajax success function 中调用它,即在 ajax 执行之后:

alert($("td#myid").attr('title'));

.html() 为您提供整个 html 而不仅仅是标题。

还要注意,对于通过 ajax 接收到的任何数据,只有在 ajax 调用成功完成后才需要访问它。当 ajax 调用被触发时,如何在文档就绪时使用它?

【讨论】:

    【解决方案2】:

    html 返回 innerHtml 属性 你需要使用

    $("td#myid").attr("title");
    

    $("td#myid").prop("title");
    

    取决于您的 jquery 版本。

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      • 1970-01-01
      • 2018-09-01
      • 2019-08-09
      • 2011-11-08
      相关资源
      最近更新 更多