Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于下拉选择动态生成文本字段和相应标签_Javascript_Select - Fatal编程技术网

Javascript 基于下拉选择动态生成文本字段和相应标签

Javascript 基于下拉选择动态生成文本字段和相应标签,javascript,select,Javascript,Select,如果用户选择下拉菜单“航班号”,则只应输入一个文本字段和相应的标签。如果用户选择下拉、全部,则应生成多个文本字段,例如用于获取航班号、来源地、目的地等的输入。“我希望使用JavaScript完成它” 下面的代码按照我的要求工作,但是如何防止select从正常的表格对齐中移开 一旦调用“更改”事件,将进行下拉选择,根据选择生成所需字段,但“选择”下拉列表将偏离结果中的正常对齐方式。“如何防止这种情况发生,为什么会发生?” 隐藏/显示 功能显示(obj、id1、id2) { txt=obj.opt

如果用户选择下拉菜单“航班号”,则只应输入一个文本字段和相应的标签。如果用户选择下拉、全部,则应生成多个文本字段,例如用于获取航班号、来源地、目的地等的输入。“我希望使用JavaScript完成它”

下面的代码按照我的要求工作,但是如何防止select从正常的表格对齐中移开

一旦调用“更改”事件,将进行下拉选择,根据选择生成所需字段,但“选择”下拉列表将偏离结果中的正常对齐方式。“如何防止这种情况发生,为什么会发生?”


隐藏/显示
功能显示(obj、id1、id2)
{
txt=obj.options[obj.selectedIndex]。值;
document.getElementById(id1.style.display='none';
document.getElementById(id2.style.display='none';
if(txt.match(id1))
{
document.getElementById(id1.style.display='block';
}
if(txt.match(id2))
{
document.getElementById(id2.style.display='block';
}
}
类型:
请选择选项
形象
文本
看不见的
文本颜色:
图片:
X坐标:
Y坐标:
文本颜色:
显示:
来访者
击打

您可以使用
variable\u name.setVisible(布尔值)
属性根据条件隐藏或取消隐藏元素。如果要隐藏搜索按钮,可以使用
JsearchButton.setVisible(false);
这里JsearchButton是搜索按钮的变量名。请参阅我为您的需求编写的示例。我希望这是有用的

这个构造函数最初会在应用程序启动时使所有元素都不可见

  public class AirportForm extends javax.swing.JFrame {

    /**
     * Creates new form AirportForm
     */
    public AirportForm() {
        initComponents();
        FlightNo.setVisible(false);
            EnterFlightNoTextBox.setVisible(false);
            From.setVisible(false);
            To.setVisible(false);
           SelectFromStationDropDown.setVisible(false);
           SelectToStationDropDown.setVisible(false);
    }
这是下拉用户选择的代码。根据用户选择,将显示元素

private void SelectSearchCriteriaActionPerformed(java.awt.event.ActionEvent evt) {                                                     
    // TODO add your handling code here:

    String search1="Flight No";
    String search2="All";
    String search3="Select An Item";

    if(SelectSearchCriteria.getSelectedItem().toString()==search1){
        FlightNo.setVisible(true);
        EnterFlightNoTextBox.setVisible(true);
        From.setVisible(false);
        To.setVisible(false);
       SelectFromStationDropDown.setVisible(false);
       SelectToStationDropDown.setVisible(false);
    }
    else if(SelectSearchCriteria.getSelectedItem().toString()==search2){
        FlightNo.setVisible(true);
        EnterFlightNoTextBox.setVisible(true);
        From.setVisible(true);
        To.setVisible(true);
       SelectFromStationDropDown.setVisible(true);
       SelectToStationDropDown.setVisible(true);
    }
}  
这是用于声明元素的

// Variables declaration - do not modify                     
private javax.swing.JTextField EnterFlightNoTextBox;
private javax.swing.JButton FinalSearchButton;
private javax.swing.JLabel FlightNo;
private javax.swing.JLabel From;
private javax.swing.JComboBox SelectFromStationDropDown;
private javax.swing.JComboBox SelectSearchCriteria;
private javax.swing.JLabel SelectSearchType;
private javax.swing.JComboBox SelectToStationDropDown;
private javax.swing.JLabel To;
// End of variables declaration                   

请指定您正在开发的应用程序、平台以及开发该应用程序所使用的工具。同时请说明您迄今为止所尝试的方法。为了便于任何人分析,并为机场提供更好的解决方案,在windows7中使用netbeans,我想根据下拉选择和基于选择。必须生成各种字段。感谢规范,但如何在“jsp页面”中实现它。是否可以使用javascript和简单按钮、html按钮、下拉列表来实现它,我对Jbuttons不太了解,但提前感谢。特别感谢@Maruthi为我记下了代码
// Variables declaration - do not modify                     
private javax.swing.JTextField EnterFlightNoTextBox;
private javax.swing.JButton FinalSearchButton;
private javax.swing.JLabel FlightNo;
private javax.swing.JLabel From;
private javax.swing.JComboBox SelectFromStationDropDown;
private javax.swing.JComboBox SelectSearchCriteria;
private javax.swing.JLabel SelectSearchType;
private javax.swing.JComboBox SelectToStationDropDown;
private javax.swing.JLabel To;
// End of variables declaration