猿问

尝试使用 Javascript 输出到文本框

我正在创建一个通信生成器,它将标准化关于我公司的关键 IT 事件的 SMS 通信。我有一个 IF/ELSE 语句,用于确定问题是新的、更新的还是已解决的,以便将必要的信息汇总在一起并相应地对其进行格式化。据我所知,这里的一切都很好,但是我在写入文本框('smsToSend')时遇到了问题,应该允许用户在将文本复制到我们的短信发送器应用程序之前进行查看,因为没有正在输出到此框中。


function generateSMS(){

 var issueTitle = document.getElementById("incidentTitle");

 var advisorImpact = document.getElementById("advisorImpact";

 var incidentUpdate = document.getElementById("incidentUpdate");

 var incidentStatus = document.getElementById("incidentState");

 var startTime = document.getElementById("startTime");

 var endTime = document.getElementById("endTime");

 var incidentPriority = document.getElementById("incidentPriority");

 var incidentBrand = "TechTeam";

 var systemImpacted = document.getElementById("systemImpacted");

 var incidentReference = document.getElementById("incidentReference");


 var smsToSend = document.getElementById("smsToSend");


 if (incidentStatus != "Closed"){

     smsToSend = "P" + incidentPriority + " " + incidentBrand + "IT RESOLVED: " + systemImpacted + ": " + incidentUpdate + ": Start: " + startTime + " End: " + endTime + " Reference: " + incidentReference;

}

else{

     if (incidentUpdate == "We are investigating this issue"){

         smsToSend = "P" + incidentPriority + " " + incidentBrand + "IT ISSUE: " + systemImpacted + ": " + issueTitle + ". " + advisorImpact + ": " + incidentReference;

     }

     else {

         smsToSend = "P" + incidentPriority + " " + incidentBrand + "IT UPDATE: " + systemImpacted + ": " + incidentUpdate + ": " + incidentReference;

     }

 }


}

generateSMS();

alert.getElementById(smsToSend);


芜湖不芜
浏览 287回答 2
2回答

守候你守候我

尝试将所有分配替换为smsToSend这样:smsToSend = yourValue;有了这个:smsToSend.value = yourValue;您的问题发生是因为smsToSend是元素的实例,而不是链接到显示文本的变量。要更新元素的值,您必须更改value元素的属性。

肥皂起泡泡

将值设置为文本框的正确方法是var smsToSend = document.getElementById("smsToSend");smsToSend.value = "Your value";
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答