私はjavascript/jQuery No0bで、addEventListenerを使用して要約ページに進行状況を出力しようとしています。これは 4 つのタブ付きのフォームです。
HTML:
<table>
<tr>
<td id="summaryCustomerName"></td>
<td id="summaryAccountManager"></td>
<td id="summaryDescription"></td>
</tr>
<tr>
<td id="summaryAccountCoordinator1"></td>
<td></td>
<td></td>
</tr>
</table>
JS の一部:
(function(){
$(document).ready(function () {
if (window.addEventListener) {
document.getElementById("accountCoordinator1").addEventListener("change", accountCoordinator1GV, false);
}
else if (window.attachEvent) {
document.getElementById("accountCoordinator1").attachEvent("change", accountCoordinator1GV);
}
});
これは問題なく動作します。customerDescription部分のみを+ customerDescription<div class='summaryDIV'>
+</div>
私が問題を抱えている部分:
var accountCoordinator1GV = function () {
var accountCoordinator1GV = "<h3>Account Coordinator</h3>" + "<div class='summaryDIV'>" + accountCoordinator1GV + "</div>";
accountCoordinator1GV += document.getElementById("accountCoordinator1").value;
document.getElementById("summaryAccountCoordinator1").innerHTML = accountCoordinator1GV;
};
次のような他の方法を試しました。
var accountCoordinator1GV = function () {
var accountCoordinator1GV = $("#accountCoordinator1").val();
var ac1DIV = "<div class='summaryDIV'>" + accountCoordinator1GV + "</div>";
$("#summaryAccountCoordinator1").append(ac1DIV);
};
ヘルプ!私は何を間違っていますか?
関数全体としてのコードは次のとおりです。
(function(){
$(document).ready(function () {
if (window.addEventListener) {
document.getElementById("customerName").addEventListener("change", customerNameGV, false);
document.getElementById("accountManager").addEventListener("change", accountManagerGV, false);
document.getElementById("customerDescription").addEventListener("change", customerDescriptionGV, false);
document.getElementById("accountCoordinator1").addEventListener("change", accountCoordinator1GV, false);
document.getElementById("ContactSubmitButton").addEventListener("click", CompanyContacts, false);
} else if (window.attachEvent) {
document.getElementById("customerName").attachEvent("change", generalInformation);
document.getElementById("accountManager").attachEvent("change", accountManagerGV);
document.getElementById("customerDescription").attachEvent("change", customerDescriptionGV);
document.getElementById("accountCoordinator1").attachEvent("change", accountCoordinator1GV);
document.getElementById("ContactSubmitButton").attachEvent("click", CompanyContacts);
}
});
var customerNameGV = function () {
var customerNameGV = "<h3>Customer Name</h3>";
customerNameGV += document.getElementById("customerName").value;
document.getElementById("summaryCustomerName").innerHTML = customerNameGV;
};
var accountManagerGV = function () {
var accountManagerGV = "<h3>Account Manager</h3>";
accountManagerGV += document.getElementById("accountManager").value;
document.getElementById("summaryAccountManager").innerHTML = accountManagerGV;
};
var customerDescriptionGV = function () {
var customerDescriptionGV = "<h3>Customer Description</h3>";
customerDescriptionGV += document.getElementById("customerDescription").value;
document.getElementById("summaryDescription").innerHTML = customerDescriptionGV;
};
var accountCoordinator1GV = function () {
var accountCoordinator1GV = "<h3>Account Coordinator</h3>" + "<div class='summaryDIV'>" + accountCoordinator1GV + "</div>";
accountCoordinator1GV += document.getElementById("accountCoordinator1").value;
document.getElementById("summaryAccountCoordinator1").innerHTML = accountCoordinator1GV;
};
var accountCoordinator1GV = function () {
var accountCoordinator1GV = $("#accountCoordinator1").val();
var ac1DIV = "<div class='summaryDIV'>" + accountCoordinator1GV + "</div>";
$("#summaryAccountCoordinator1").append(ac1DIV);
};
})();