Javascript 更改textarea字段、HTML、JS、jQuery

Javascript 更改textarea字段、HTML、JS、jQuery,javascript,jquery,html,button,textarea,Javascript,Jquery,Html,Button,Textarea,我有7个按钮(带有不同图像(徽标)的不同合作伙伴按钮) 如您所见,它们都有不同的方法来打开带有textarea的模式窗口 <div class="hidden" id="buttonX"> <div class="login-form"> <div class="login-form-inner"> <textarea id

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


如您所见,它们都有不同的方法来打开带有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的值。 如果我单击
按钮,在模式窗口中,我需要有一个包含此按钮代码的文本区域


如何实现这一点?

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

我在所有按钮中添加了一个类(“myCBtn”),然后在
中克隆了该按钮。之后,您只需要获取创建的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>
并将单击功能更新为以下内容:

$('.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);
    });
$('.myCBtn')。单击(函数(e){
var thisbutton=$(this.clone();
var newDiv=$('').append(此按钮);
var buttoncode=$(newDiv.html();
//在此处使用buttoncode执行下一步操作。
$(“#按钮编码”).val(按钮编码);
});

更新了JSFIDLE:

所以据我所知,您有一个模式窗口,其中包含代码和几个按钮。单击按钮,您希望更改一些文本。我说得对吗?是的,您说得对,先生。因为若textarea被读取为字符串,那个么您必须手动替换它。由于它有代码,您可以检查必要的标识符并替换value属性。一个合适的工作示例会更好地帮助您。您可以添加一把小提琴吗?您可以在这里找到实时站点。添加$('.myCBtn')。在添加jQuery库链接后,单击页面末尾的(函数(e){。好的!你救了我的命!非常感谢!它很有效!抱歉,我很高兴地忘记了;)再次感谢你!答案已接受!
<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);
    });