0

我想要每个 URL 旁边的 4 个按钮,然后您可以单击一个按钮将父 URL 复制到按钮各自的文本字段。

我认为使用 jquery 最容易做到这一点,但我不知道从哪里开始。任何建议将不胜感激!

http://jsfiddle.net/WwdMw/

<div class="selection">
  <div class"url">
    <h2>example1.com</h2>
  </div>
  <button type="button" class="btn_opt1">Copy to Option1</button>
  <button type="button" class="btn_opt2">Copy to Option2</button>
  <button type="button" class="btn_opt3">Copy to Option3</button>
  <button type="button" class="btn_opt4">Copy to Option4</button>
</div>
<hr/>
<div class="selection">
  <div class"url">
    <h2>example3.com</h2>
  </div>
  <button type="button" class="btn_opt1">Copy to Option1</button>
  <button type="button" class="btn_opt2">Copy to Option2</button>
  <button type="button" class="btn_opt3">Copy to Option3</button>
  <button type="button" class="btn_opt4">Copy to Option4</button>
</div>
<hr/>

<div class="selection">
  <div class"url">
    <h2>example2.com</h2>
  </div>
  <button type="button" class="btn_opt1">Copy to Option1</button>
  <button type="button" class="btn_opt2">Copy to Option2</button>
  <button type="button" class="btn_opt3">Copy to Option3</button>
  <button type="button" class="btn_opt4">Copy to Option4</button>
</div>

<hr/>
4

1 回答 1

1

有它。

$('button').click(function () {
    var value = $(this).parent().find('h2').text();
    var idIdentifier = $(this).text().substr($(this).text().length - 1);
    var textArea = $('div[class*='+idIdentifier+']').find('textarea');
    textArea.val(textArea.val() +" "+ value);
})

现场演示

于 2013-10-24T17:10:13.257 回答