我是一个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 部分转换为 <div class='summaryDIV'>
+ customerDescription + </div>
< / b>
我遇到问题的部分:
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);
};
HELP!我究竟做错了什么?
以下是代码的全部功能:
(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);
};
})();
答案 0 :(得分:1)
换行
var ac1DIV = "<div class='summaryDIV'>" + accountCoordinator1GV + "</div>";
as
var ac1DIV = $("<div class='summaryDIV'>" + accountCoordinator1GV + "</div>");
试
var accountCoordinator1GV = function () {
var accountCoordinator1GV = $("#accountCoordinator1").val();
var ac1DIV = $("<div class='summaryDIV'>" + accountCoordinator1GV + "</div>");
$("#summaryAccountCoordinator1").append(ac1DIV);
};
答案 1 :(得分:0)
谢谢!这就是我为解决这个问题所做的,愚蠢的错误,感谢TON的捕获!
var accountCoordinator1GV = function () {
var accountCoordinator1GV = $("#accountCoordinator1").val();
var ac1DIV = $("<h3>Account Coordinator</h3>" + "<div class='summaryDIV'>" + accountCoordinator1GV + "</div>");
$("#summaryAccountCoordinator1").append(ac1DIV);
};