[英]jQuery - Append and Remove HTML code
在jQuery中,如何將HTML行添加到某些HTML中,以及刪除HTML行?
這是前面的代碼:
<div class="form-group">
<label class="control-label col-md-2" for="txtCvc">Cvc</label>
<div class="col-md-10">
<input class="form-control text-box single-line" id="txtCvc" name="Cvc" type="text" value="" />
</div>
</div>
這是后面的代碼:
<div class="form-group">
<label class="control-label col-md-2" for="txtCvc">Cvc</label>
<div class="col-md-10">
<input class="form-control text-box single-line" id="txtCvc" name="Cvc" type="text" value="" />
<span class="field-validation-error" data-valmsg-for="txtCvc" data-valmsg-replace="true">Test message.</span>
</div>
</div>
我需要添加這行代碼:
<span class="field-validation-error" data-valmsg-for="txtCvc" data-valmsg-replace="true">Test message.</span>
另外,相反。 如何刪除這行代碼?
這是前面的代碼:
<div class="form-group">
<label class="control-label col-md-2" for="txtCvc">Cvc</label>
<div class="col-md-10">
<input class="form-control text-box single-line" id="txtCvc" name="Cvc" type="text" value="" />
<span class="field-validation-error" data-valmsg-for="txtCvc" data-valmsg-replace="true">Test message.</span>
</div>
</div>
這是后面的代碼:
<div class="form-group">
<label class="control-label col-md-2" for="txtCvc">Cvc</label>
<div class="col-md-10">
<input class="form-control text-box single-line" id="txtCvc" name="Cvc" type="text" value="" />
</div>
</div>
對不起,我忘了提到我是jQuery的初學者。 我正在查看追加和刪除功能。 提前致謝。
如果你使用show()和hide()來表示錯誤信息會更合適
$('.field-validation-error').show();
用於顯示消息和
$('.field-validation-error').hide();
隱藏它,使用if else來檢查你的狀況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.