繁体   English   中英

jQuery:包含textarea值的div,当我单击div中的一个单词时,使其在textarea中单击

[英]Jquery: a div that contains the value of a textarea, when i click on a word in the div, make it click there in the textarea

我有一个div,其中包含keyup上textarea的值,所以当我键入textarea时,它就显示在div中,div是textarea的注释预览。 当我在div中单击时,是否可以模拟文本区域中的单击? 因此,如果在div中我单击句子“你好,我在你身上”中的“世界”一词,那么它将模拟在文本区域中同一点上对相同单词的单击?

有没有办法用jQuery做到这一点?

模拟在文本区域中同一点上对相同单词的点击

我想很难在textarea中捕获文本的确切位置,但是您可以在下面做一些事情(尽管它不能满足您的要求)。 请尝试了解。 我觉得这很困难,因为,仅单击<div />标记中的某些文本并不能给出Word的偏移位置。 如果您要在div中选择一些文本,可能对这篇文章有所帮助。

但我想了解是否可以仅使用.click()

如果有人提出了一个很酷的想法,那将更有帮助=)

HTML

<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Avinash</title>

<style>
  #input , #output { margin: 20px;width:300px;height:200px; border:1px solid #000; font 15px Arial; }
  #output {overflow:scroll;float:left; font:bold 14px verdana; color : #0099b9; }
</style>
</head>
<body>
  <table>
    <tr>
      <td>
        <textarea id="input" >Type your Text </textarea>
      </td>
      <td>
        <div id="output" > </div>
      </td>
    </tr>
  </table>
  </span>
</body>
</html>

JavaScript

   $(function() {
      $('#input').one('focus',function() {
          $(this).val('');
      }).bind('keyup',function() {
        $('#output').text($(this).val());
      });

      $('#output').bind('click',function() {
        alert('focusing Textarea');
        $('#input').focus();
      });
    });

您可以在此处测试以上代码: http : //jsbin.com/atuqo4

隐藏父 div 时包含<textarea>&lt;i&gt;?&lt;/div&gt;&lt;/i&gt; &lt;b&gt;?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我有一个由其内容动态生成的 div 结构。 它看起来像这样:</p><pre> &lt;div class="fpd-list-row fpd-add-layer" id="1609962837979"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;Dein Foto&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-icon-add"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="fpd-list-row" id="1609962838288"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span class="fpd-current-color" style="background: #ffffff" data-colors=""&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;&lt;textarea&gt;Wanderlust&lt;/textarea&gt;&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-lock-element"&gt;&lt;span class="fpd-icon-unlocked"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</pre><p> 我只想隐藏 textareas 和 parent 元素到 .fpd-list-row 但保持其他 div like.fpd-list-row.fpd-add-layer 不变。 当我将 textarea 设置为不显示时,父 div 仍然存在。 有没有办法仅在包含&lt;textarea&gt;时将父 div 隐藏到 ..fpd-list-row ?</p></div>

[英]Hide parent div when it contains <textarea>?

暂无
暂无

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

相关问题 如何使div元素可编辑(当我点击它时就像textarea一样)? 当我单击评论系统javascript而不是jquery上的回复按钮时,显示textarea或div(在要回复的评论下方) 我如何从包含div的textarea中获取价值 单击按钮(包括内容)时,如何用textarea替换div? 在按钮单击时将文本从textarea附加到div 单击将文本从div添加到textarea 隐藏父 div 时包含<textarea>&lt;i&gt;?&lt;/div&gt;&lt;/i&gt; &lt;b&gt;?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我有一个由其内容动态生成的 div 结构。 它看起来像这样:</p><pre> &lt;div class="fpd-list-row fpd-add-layer" id="1609962837979"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;Dein Foto&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-icon-add"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="fpd-list-row" id="1609962838288"&gt;&lt;div class="fpd-cell-0"&gt;&lt;span class="fpd-current-color" style="background: #ffffff" data-colors=""&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="fpd-cell-1"&gt;&lt;textarea&gt;Wanderlust&lt;/textarea&gt;&lt;/div&gt;&lt;div class="fpd-cell-2"&gt;&lt;span class="fpd-lock-element"&gt;&lt;span class="fpd-icon-unlocked"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</pre><p> 我只想隐藏 textareas 和 parent 元素到 .fpd-list-row 但保持其他 div like.fpd-list-row.fpd-add-layer 不变。 当我将 textarea 设置为不显示时,父 div 仍然存在。 有没有办法仅在包含&lt;textarea&gt;时将父 div 隐藏到 ..fpd-list-row ?</p></div> 单击单选按钮jQuery时隐藏文本区域 我单击提交按钮时,用jQuery扩展了textarea,但未提交表单 在JQUERY的div元素中检索textarea值
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM