Jqueryを使用して隠しフィールドを設定しようとしているときに、プレーンなJavaスクリプトを使用しても、奇妙な問題に直面しています
JSP ページに 2 つの非表示フィールドがあります
<input type="hidden" name="firstSelectedPaymentId" id="firstSelectedPaymentId1" value=""/>
<input type="hidden" name="secondSelectedCCPaymentId" id="secondSelectedCCPaymentId" value=""/>
これがJSで隠し値を設定する方法です
if ($('#firstSelectedPaymentId1').length > 0) {
$('#firstSelectedPaymentId1').val(response.result.selectedPaymentInfoId);
}
if ($('#secondSelectedCCPaymentId').length > 0) {
//$('#secondSelectedCCPaymentId').val(response.result.selectedPaymentInfoId);
document.getElementById('secondSelectedCCPaymentId').value=response.result.selectedPaymentInfoId;
}
最初のケースでは正常に動作していsecondSelectedCCPaymentIdますが、非表示フィールドに値を設定していません。
私はすでに JSP をチェックしましたが、同じ id のフィールドがありません。
alert($('#secondSelectedCCPaymentId').val());
のようなアラート ボックスで値を確認できます5466565665666。response.result.selectedPaymentInfoIdはシステムによって生成された値であり、既に検証済みのシステムによって生成されています。どこが間違っているのかわからない、または非表示フィールドに値を設定していないのはなぜですか?