2012-06-03 18 views
2

东西,我有一个像JQuery的未来selecter或类似

<ul> 
    <li>Some Name <a class="rud" href="#">remove</a><input type="text" value="one" readonly="readonly" name="array" /></li> 
    <li>Some other name <a class="rud" href="#">remove</a><input type="text" value="two" readonly="readonly" name="array" /></li> 
</ul> 

我希望当我<a>单击重命名输入名称和值的HTML代码。

结果应该是

<li>Some Name <a class="rud" href="#">undo</a><input type="text" value="one" readonly="readonly" name="deleted" /></li> 

jQuery的文件上点击就绪事件

$(document).ready(function() { 
     $(".rud").click(function() { 
      // alert(this).next().val(); 
      // get input button in this <li></li>. 
      // change name 
      $(this).text("undo"); 



     }); 
    }); 

回答

5
$(".rud").click(function() { 
    $(this) 
     .text("undo") // change link text 
     .next(':input') // go to nex input 
     .attr('name','deleted'); // chage name attr 
});​ 

DEMO

+0

完美! ..等待我的CD能够使这个答案为“接受”:) –

+0

@NovkovskiStevoBato谢谢,很高兴帮助 – thecodeparadox

+0

@RobKielty所以最新怎么样 – thecodeparadox