因此,我试图启用多个具有类名称= textfieldToClose
的文本框,但是以下代码将不起作用。
var collection = document.getElementsByClassName('textfieldToClose');
$('#edit').click(function() {
event.preventDefault()
for (var i = 0; i < collection.length; i++) {
collection[i].style.border = '1px black solid' ? '' : '1px black solid';
collection[i].enabled = true;
}
document.getElementById("save1").style.display = "inline-block";
document.getElementById('edit').setAttribute("disabled", "disabled");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row pl-4 pt-1 pb-1 border" style="width: 100%;">
<div class="altright">
<input type="text" value="Value 1" disabled style="background-color: transparent;border: none" class="textfieldToClose" name="pkgname1"></input>
</div>
<div class="altright">
<input type="text" value="123Rs" disabled style="background-color: transparent;border: none" class="textfieldToClose" name="pkgprice1"></input>
</div>
<button type="button" id="edit">Edit</button>
</div>
答案 0 :(得分:1)
</input>
是不必要的(或有效的)。只需使用/>
这是我的建议
var $collection = $('.textfieldToClose');
$('#edit').click(function(e) {
e.preventDefault(); // not really necessary since it is type="button"
$collection.each(function() { $(this).removeAttr("disabled") })
$("#save1").show();
$(this).prop("disabled", true);
});
.textfieldToClose { border: 1px black solid; }
.textfieldToClose:disabled { background-color: transparent;border: none;}
#save1 { display:none }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row pl-4 pt-1 pb-1 border" style="width: 100%;">
<div class="altright">
<input type="text" value="Value 1" disabled class="textfieldToClose" name="pkgname1" />
</div>
<div class="altright">
<input type="text" value="123Rs" disabled class="textfieldToClose" name="pkgprice1" />
</div>
<button type="button" id="edit">Edit</button>
<button type="button" id="save1">Save</button>
</div>