简体   繁体   English

单击带有JavaScript的href后如何编辑3个标签的值?

[英]how to edit value of 3 labels after clicking on a href with javascript?

I want to make three different labels editable when I click on a single href 我想在单击单个href时使三个不同的标签可编辑
I have: 我有:

<tr>
    <td align="left">PLZ:</td>

    <td>
        <label for="name" class="control-label">
            <p class="text-info">
                <label style="color: #662819;" id="plz"></label>
                <i class="icon-star"></i>
            </p>
        </label>
        <input type="text" class="edit-input" />

        <div class="controls">
            <a class="edit" href="#">Daten sichern</a>
        </div>
    </td>
</tr>

changing this one label with: 使用以下方法更改此标签:

CSS: CSS:

.edit-input {
    display:none;
}

JQuery: jQuery的:

$(function() {
    $('a.edit').on("click", function(e) {
        e.preventDefault();
        var dad = $(this).parent().parent();
        var lbl = dad.find('label');
        lbl.hide();
        dad.find('input[type="text"]').val(lbl.text()).show().focus();
    });

    $('input[type=text]').focusout(function() {
        var dad = $(this).parent();
        $(this).hide();
        dad.find('label').text(this.value).show();
    });
});

how to do it for 2 or more labels??? 如何针对2个或更多标签进行处理??? like for follow ones...: 喜欢追随者...:

<tr>
      <td align="left">Strasse:</td>
      <td>
        <label for="name" class="control-label">
            <p class="text-info">
                <label style="color: #662819;" id="street"></label>
                <i class="icon-star"></i>
            </p>
        </label>
        <input type="text" class="edit-input" />  
      </td>
</tr>

and so on... 等等...

To make different labels editable at the same time, when you click a single link, you can use JQuery's each function, as shown in the following code: 为了使不同的标签可同时编辑,单击一个链接时,可以使用JQuery的each函数,如以下代码所示:

$('a.edit').on('click',function(e){
    e.preventDefault();

    //Search for .control-label items
    $('label.control-label').each(function(key,item){
        var label = $(item);          
        label.hide();
        label.siblings('input.edit-input').val(label.text()).show().focus();
    });

});

Hope it helps! 希望能帮助到你!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM