English 中文(简体)
JQuery的 Chang变
原标题:Changing td s html in JQuery

I want to change text in table td from 1,1,1 to 1,2,3 with jQuery
But it not seem to work. what is wrong in my code?

这是我的 Java本功能。

    function reorder(targetId){
        var i = 1;
        jQuery.find(targetId).each(function(){
            jQuery(this).attr("innerHTML", i);
            i ++;
        });
    }

我的html代码。

<form>
    <input type="button" onClick="reorder( #index );" value="test"/>
    <table>
        <tr><td id="index">1</td></tr>
        <tr><td id="index">1</td></tr>
        <tr><td id="index">1</td></tr>
    </table>
</form>
问题回答

你们在那里一片混杂的.子。 ......

function reorder(selector){
     jQuery(selector)
      .find( tr td:first-child )
      // Remove the + 1 if you want it to start at 0.          
      .html(function(i) { return i + 1; });
}

这里有一些变化......

  • Changed your argument variable to be clearer.
  • You can use jQuery( selector ), not jQuery.find().
  • You can use the html() method.

值得一提的是,如果你不使用另一个图书馆(或不打算使用),你可以使用<条码><<> > /代码>,该代码比<条码>缩短。

我也修改了你的超文本。

<form>
    <input type="button" onclick="reorder( #my-table );" value="test"/>
    <table id="my-table">
        <tr><td>1</td></tr>
        <tr><td>1</td></tr>
        <tr><td>1</td></tr>
    </table>
</form>

您可能认为,使用多种<代码>id的属性,其价值相同,其标记无效。 你们可以在那里使用一个班子,或者更不用说。 你可能不关心有效标识,但浏览器CSS和Javad 字典could在(现在或将来)期望有<条码>id/条码>赋予独一无二之处。

我认为,你们需要改变价值观的增量表述。

function reorder(targetId){
        var i = 1;
        jQuery.find(targetId).each(function(){
            jQuery(this).attr("innerHTML", i);
            i++; // Before that it was i ++ 
        });
    }




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签