更改文本区域字段,HTML,JS,jQuery

Changing the textarea field, HTML, JS, jQuery

我有 7 个按钮(具有不同图像(徽标)的不同合作伙伴按钮)。

<a class="button button-type-1 fancybox_js" href="#buttonX">
<a class="button button-type-2 button-gray fancybox_js" href="#buttonX">
<a class="button button-type-2 button-orange fancybox_js" href="#buttonX">

如你所见,它们都有不同的打开模式 window with textarea

<div class="hidden" id="buttonX">
    <div class="login-form">
        <div class="login-form-inner">
            <textarea id="button1" name="something"></textarea>

这个文本区域里面必须是被按下的这个按钮的代码

<a class="button button-type-1 fancybox_js" href="#buttonX"> if pressed this button

但我需要根据单击的按钮更改 textarea 的值。 如果我单击 <a class="button button-type-2 button-orange fancybox_js" href="#buttonX"> 按钮,在模态 window 中,我需要一个带有此按钮代码的文本区域。

我怎样才能使这个工作?

您可以使用 jQuery 的 clone() 和 html() 方法获取按钮的代码。

我已将 class("myCBtn") 添加到您的所有按钮,然后将按钮克隆到 <div>。之后你只需要使用创建的 DIV 的 HTML 来获取你的按钮的代码。

HTML 个按钮。

<td width="50%"><a class="button myCBtn button-type-1 button-blue-round fancybox_js" href="#buttonX"><span>Купить в кредит1</span></a><br>

<a class="button myCBtn button-type-1 fancybox_js" id="button_1" href="#buttonX"><span>Купить в кредит4</span></a><br>

<a class="button myCBtn button-type-2 button-gray fancybox_js" href="#buttonX"><span>Купить в кредит2</span></a><br>

<a class="button myCBtn button-type-2 button-orange fancybox_js" href="#buttonX"><span>Купить в кредит3</span></a><br></td>

更改以下代码

<div class="myCBtn" id="myCBtn">
    <textarea id="myCBtn" name="ButtonCode"></textarea>
</div>

<div class="popupDivClass" id="popupDivId">
    <textarea id="buttonCodeTA" name="ButtonCode"></textarea>
</div>

同时删除下面的行。

document.getElementById('myCBtn').value = buttoncode;

并将点击功能更新为:

$('.myCBtn').click(function(e){
            var thisbutton=$(this).clone();
        var newDiv=$('<div>').append(thisbutton);
        var buttoncode=$(newDiv).html();
        // perform next operations here using buttoncode.
        $("#buttonCodeTA").val(buttoncode);
    });

更新了 jsFiddle:https://jsfiddle.net/7o6p8nso/1/