简体   繁体   English

javascript:如何在Statement中使用变量值?

[英]javascript: How to use the variable value inside a Statement?

How can I use the variable value inside a Statement? 如何在语句中使用变量值? It goes like this: 它是这样的:

var skillsSelect = document.getElementById("selUnidade");           
var unidade = skillsSelect.options[skillsSelect.selectedIndex].text;
if ( unidade == "" ) {
    alert("Escolha uma Unidade de Estoque!");
    return false;
}
else
{
    alert("Cheguei!");
    self.opener.document.frmIncluir.id_Unidade.value = unidade; 
}
var message = "Foo Bar " + unidade + " blah blah";
alert(message);

Your value assignment syntax is OK. 您的值分配语法是可以的。 The problem will be with your code that targets the input on the opener page. 问题将在于您的代码针对打开器页面上的输入。

self.opener.document.frmIncluir.id_Unidade.value = unidade; 

On this line, frmIncluir needs to be the form name (not ID) and id_Unidade needs to be the input element name (not ID). 在这行上, frmIncluir必须是表单名称 (不是ID),而id_Unidade必须是输入元素名称 (不是ID)。

If id_Unidade is the ID you could change it to: 如果id_Unidade是ID,则可以将其更改为:

self.opener.document.getElementById("id_Unidade").value = unidade; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM