问题描述:

So I am inserting dynamically a strike element, but it is rendering in the HTML markup but not showing up visually. The Chrome inspector shows that the strike element is added. Is it because I am adding it around input elements?

Here's the jQuery

$("#ResidentialStandardPeriod").change(function () {

period = $("#ResidentialStandardPeriod").val();

console.log(period);

if (period == $('#' + period).attr('id')) {

$('#' + period).attr('disabled', true).wrap("<strike>")

$('input[type=checkbox]').not('#' + period).attr('disabled', false);

}

});

网友答案:

You can't wrap input element with </del>, coz that wont show any effect on input but you can wrap next element, in your case number. I would prefer you to wrap your number in <span> and then target that span.

HTML

<input type="checkbox" value="1" id="1"><span>1</span><br>
<input type="checkbox" value="1" id="2"><span>2</span><br>
<input type="checkbox" value="1" id="3"><span>3</span><br>
<input type="checkbox" value="1" id="4"><span>4</span><br>

JQuery

 $('#Period').change(function(){
        period = $('#Period').val();
        $("span").unwrap();
        console.log(period);
        if (period == $('#'+period).attr('id')){
            $('#'+period).attr('disabled',true).next("span").wrap("<del/>");
            $('input[type=checkbox]').not('#'+period).attr('disabled', false);
        }
    });

DEMO

相关阅读:
Top