<div class="main">
<button class="btnClick" type="button"> </button>
<button class="btnClick" type="button"> </button>
<div class="child">
<p> ** Some child Text ** </p>
<textarea id="edit" class="hidden"></textarea> //class hidden == Display:none
</div>
</div>
<div class="main">
<button class="btnClick" type="button"> </button>
<button class="btnClick" type="button"> </button>
<div class="child">
<p> ** Some child Text ** </p>
<textarea id="edit" class="hidden"></textarea> //class hidden == Display:none
</div>
</div>
我正在尝试使用以上代码实现edit部分。上面<div>
是动态生成的,当用户单击按钮时,我需要隐藏该<p> "** Some child Text ** " and make the Textarea visible
特定Div的并复制
文本区的一部分
我尝试了“按一下按钮”
$(this).closest('#edit').removeClass("hidden");
但它不起作用,并且每次我都看到第一个文本区域时,无论我单击哪个按钮,都与其他代码一起使用
寻找的是在第一个按钮上单击特定 <div> textarea class hidden to be removed and copy the<p> text to Textarea on that particula <div>
做这个的最好方式是什么。我可以添加任何新类,并使代码通用。你的想法!
您应该从文本区域中删除该ID,以避免有多个相同的ID。
此功能可以满足您的需求。
$(document).on('click', '.btnClick', function(){
//cache the child div block (everything you want is in here)
child = $(this).next('.child');
//hide the p tag
child.find('p').hide();
//this copies the p tag in
child.find('textarea').val( child.find('p').html() );
//this shows the textarea
child.find('textarea').show();
});
这是一个jsfiddle:http : //jsfiddle.net/6wAUK/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句