单选和复选框选中的值获胜';无法在JavaScript中显示
我正在尝试使用JavaScript获取一个单选按钮和多个复选框的值,以显示在新窗口中。我似乎不明白为什么返回“true”而不是检查的实际值。下面是结果的代码和屏幕截图单选和复选框选中的值获胜';无法在JavaScript中显示,javascript,checkbox,radio-button,window.open,Javascript,Checkbox,Radio Button,Window.open,我正在尝试使用JavaScript获取一个单选按钮和多个复选框的值,以显示在新窗口中。我似乎不明白为什么返回“true”而不是检查的实际值。下面是结果的代码和屏幕截图 function messagebox() { 新窗口; var msg=“”; var i=document.PizzaForm.state.options.selectedIndex; var text=document.PizzaForm.state.options[i].text; var value=document.
function messagebox()
{
新窗口;
var msg=“”;
var i=document.PizzaForm.state.options.selectedIndex;
var text=document.PizzaForm.state.options[i].text;
var value=document.PizzaForm.state.options[i].value;
{document.PizzaForm.customer.value=document.PizzaForm.customer.value.replace(/\w\S*/g,函数(txt){返回txt.charAt(0.toUpperCase()+txt.substr(1.toLowerCase();});}
{document.PizzaForm.city.value=document.PizzaForm.city.value.replace(/\w\S*/g,函数(txt){返回txt.charAt(0.toUpperCase()+txt.substr(1.toLowerCase();});}
新窗口=窗口。打开(“,”,“状态=否,高度=500,宽度=500”);
message=“- 名称:”+document.PizzaForm.customer.value;
消息+=”
- 地址:“+document.PizzaForm.Address.value;
消息+=“
- 城市:”+document.PizzaForm.City.value;
消息+=”
- 状态:“+document.PizzaForm.State.value;
消息+=”
- 邮政编码:“+document.PizzaForm.Zip.value;
message+=”
- Phone:“+document.PizzaForm.Phone.value;
message+=“
- 电子邮件:”+document.PizzaForm.Email.value;
消息+=”
- 大小:“+showSize();
消息+=“
- 浇头:“+showToppings();
newWindow.document.write(消息);
函数showSize()
{
对于(i=0;ishowSize()
和showToppings()方法最后都返回了true
,这就是为什么您在字符串中得到了true。您应该返回msg
,您的问题就会得到解决。这是因为您在showSize()中返回了true方法。你应该返回msg。showtoppings()方法也是如此。羞愧地垂着头,它正盯着我的脸,谢谢Sushil!@Sushil你应该把它作为一个答案发布。@Sushil请这样做,我可以给你荣誉。非常欢迎你@Dovone,我将把它作为一个答案发布。请标记它。