简体   繁体   English

单击超链接时如何动态显示文本区域

[英]How can i display a textarea dynamically when i click on a hyperlink

I want to display text area dynamically inside a div when i click on a hyperlink how it can be done. 当我单击超链接时如何在div内动态显示文本区域。 Please help. 请帮忙。 Thanks.. 谢谢..

<div class="fright clr7" style="padding-top:10px;"><a href="">Reply</a></div>

<textarea name="motivo" rows="25" cols="50" style="height:100%; display:none; width: 100%" ></textarea>

You can do following; 您可以执行以下操作;

$("a").on("click", function() {
    event.preventDefault();
    if ($(".fright").find("textarea").length == 0) {
        $(".fright").append('<textarea name="test" id="test"></textarea>');
    }
});

Here is a working demo: jsfiddle 这是一个工作示例: jsfiddle

Edit: 编辑:

If you have hidden textarea you can use following; 如果您有隐藏的文本区域,则可以使用以下命令;

$("a").on("click", function() {
    event.preventDefault();
    $("textarea[name='motivo']").show();
});

Here is a working demo: jsfiddle 这是一个工作示例: jsfiddle

Something like 就像是

$('a[href*="Reply"]').click(function(){
  // update this selector
   $('textarea[name='motivo']').show();
}); 
<div class="fright clr7" style="padding-top:10px;"><a class="reply" href="">Reply</a>
<textarea style="display:none;">

</textarea>
</div>

and jquery code: 和jQuery代码:

<script type="text/javascript">

$('a.reply').click(function(){

$(this).closest('textarea').show();

return false;

});

</script>
<div class="fright clr7" style="padding-top:10px;" id="text"><a href="javascript:show()">Reply</a></div>

<script>
  function show()
  {
     document.getElementbyId("text").innerHTML="<textarea>anything here</textarea>";
  }
</script>

Try this: 尝试这个:

$("div.fright a").on("click", function(e) {
    e.preventDefault();
    if($(this).parent("div.fright").find("textarea").length==0)
    $(this).parent("div.fright").append('<textarea name="test" id="test"></textarea>');
});

DEMO DEMO

Try this way 试试这个

<div class="fright clr7" style="padding-top:10px;"><a href="">Reply</a>
</div>

<textarea name="motivo" rows="25" cols="50" style="height:100%; display:none; width: 100%" ></textarea>

JS JS

$("a:contains('Reply')").click(function(e){
   e.preventDefault()
   $('textarea[name="motivo"]').show();

}); 

DEMO DEMO

I think you need this i have used jquery 我想你需要这个我用过jQuery

<script>
 $("#Test").click(function() {
  $("#TestDiv").html("<textarea rows='4'></textarea>");
 });
</script>


<div class="fright clr7" id="TestDiv" style="padding-top:10px;"><a href="" id="Test">Reply</a></div>

<html>

<head>

<script type="text/javascript">

function showtext()

{

document.getElementById('text_a').style.display = 'block';

}

</script>

</head>

<body>

<div>

<textarea id="text_a" style="display:none;"></textarea>

<a href="javascript:showtext();">Show Textarea</a>

</div>

</body>

</html>

You can try this: 您可以尝试以下方法:

Working Fiddle here 在这里工作小提琴

$('.fright a').click(function() {
    $('.textarea').fadeIn(500);
     return false;
});

Good Luck... 祝好运...

You can create textarea on click and append inside DIV, it will be available whenever user click on link. 您可以单击创建文本区域,并在DIV内追加,只要用户单击链接即可使用。

<div class="fright clr7" style="padding-top:10px;"><a href="">Reply</a></div>

$(function(){
      $('.fright').on('click', 'a', function(e){
        e.preventDefault();
      $('<textarea />', {
          cols: 50,
          rows: 25,
          name: 'motivo',
          class: 'motivo-text'
      }).appendTo('.fright');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何动态显示浮动文本区域的上方或下方? - How can I dynamically display on or off a floating textarea? 如何记录超链接点击? - How can I log a hyperlink click? C#.net-如何使用JavaScript在单击按钮时显示动态生成的文本区域? - C#.net - How can I show a dynamically generated textarea on button click using JavaScript? 如何使用Knockout js在单击按钮时显示动态生成的textarea? - How can I show a dynamically generated textarea on button click using Knockout js? 如何通过单击HTML中的超链接重定向到另一页? - How can i redirect to another page by click on hyperlink in Html? 我正在尝试从动态生成的表单中获取Textarea值,但是当我单击按钮时,什么也没有发生 - I'm trying to get Textarea value from a dynamically generated form but when I click the button nothing happens 如何动态更改textArea文本颜色? - How can I change textArea text color dynamically? 如何在动态添加中添加 TinyMCE 编辑器<textarea> - How can I add TinyMCE Editor in dynamically added <textarea> 当我单击HyperLink时,在JS方法中获取HyperLink的父级 - Obtain Parent of HyperLink In JS method when I click on HyperLink 我可以使用JQuery代码模拟对超链接的点击吗? - Can I simulate a click on a hyperlink with JQuery code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM