gpt4 book ai didi

javascript - 如何在javascript中将对象转换为字符串?

转载 作者:行者123 更新时间:2023-11-30 07:11:32 25 4
gpt4 key购买 nike

下面我在这里粘贴了我的一段javascript代码

1)

  function showCustomerName(dropdown) {
var selectedCustomer = dropdown.options[dropdown.selectedIndex].value;
var currentCustomer = document.getElementById('currentCustomer');
alert(selectedCustomer);

var context = document.forms[0].context.value;
document.forms[0].mode.value = "UPDATE";
document.forms[0].custName.value = selectedCustomer ;
document.forms[0].action=context+"/updateReportDetail.do";
document.forms[0].method="POST";
document.forms[0].submit();
}

2)

 function showCustomerID(dropdown) {
var currentCustomer = document.getElementById('currentCustomer');
var selectedCustomerID = dropdown.options[dropdown.selectedIndex].value;
alert(selectedCustomerID);

var context = document.forms[0].context.value;
document.forms[0].mode.value = "UPDATE";
document.forms[0].custName.value = currentCustomer;
document.forms[0].custID.value = selectedCustomerID ;
document.forms[0].action=context+"/updateReportDetail.do";
document.forms[0].method="POST";
document.forms[0].submit();
}


<select id="currentCustomer" onchange="showCustomerName(this)">
<c:forEach var="Customer" items="${listCustomer}" >
<option value="<c:out value="${Customer}" />"><c:out value="${Customer}" />
</option>
</c:forEach>
</select>

<select id="currentCustomerID" onchange="showCustomerID(this)">
<c:forEach var="CustomerID" items="${listCustomerID}" >
<option value="<c:out value="${CustomerID}" />"><c:out value="${CustomerID}" />
</option>
</c:forEach>
</select>

上面的代码运行良好。问题是我需要从“showCustomerName()”到“showCustomerID()”脚本中检索值。

在“showCustomerID()”脚本方法中,我正在检索“showCustomerName()”方法值作为对象

var currentCustomer = document.getElementById('currentCustomer');

如何将其作为值检索?我不想作为对象检索

请大家帮帮我

最佳答案

只需要抓取值

var currentCustomer = document.getElementById('currentCustomer').value;
alert(currentCustomer);

虽然你应该确保它存在

var currentCustomerElement = document.getElementById('currentCustomer');
var currentCustomer = (currentCustomerElement) ? currentCustomerElement.value : "not found";

或者我误解了您要检索的内容?

关于javascript - 如何在javascript中将对象转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3558813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com