1

我使用 GWT 的 htmlflow 在我的代码中添加了一个动态文本框。现在我想从文本框中检索值。下面是代码,任何帮助都会很明显。通过使用 Rootpanel.get(elementID)。我能够得到元素值

运营商/p:

<input id="value1" 80px;="" border:="" 0px;="" border-bottom:="" 4px="" solid="" #3366ff;'="" type="textstyle='width:">

从这里我如何获得我在文本框中输入的值?

    String alertText = "If pressure > ? and glucoselevel > ? ";
     String newAlertText = alertText.replace("?", "");

    numberOfPlaceHolder = alertText.length() - newAlertText.length();
    System.out.println("Num of Place holder :"+numberOfPlaceHolder);

    String[] alertblock = alertText.split("\\?");           



    StringBuffer alertHtml = new StringBuffer();


   for(int i=1; i<=numberOfPlaceHolder;i++){   


       String textbox = "<input id='value"+i+"' type=textstyle='width: 80px; border: 0px;  border-bottom: 4px solid #3366FF;' />";
       String textblock = alertblock[i-1];
       alertHtml.append(textblock);
       alertHtml.append(textbox);              


   }



   String alertTextHtml = "<div>"+alertHtml.toString()+"</div>"; 

   htmlFlow = new HTMLFlow(alertTextHtml);

   alertTextLay.addMember(htmlFlow);

   IButton saveAlertBtn = new IButton();
   saveAlertBtn.setTitle("Save Alert");
    saveAlertBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // TODO Auto-generated method stub
            LinkedHashMap<String, String> alertValueMap = new LinkedHashMap<String, String>();
            for(int i=1; i<=numberOfPlaceHolder;i++){   

                System.out.println(**RootPanel.get("value"+i));**
                //System.out.println(DOM.getElementById("value"+i).getInnerText().toString());

            }
        }
    });
4

1 回答 1

1

我认为您必须使用 GWT Dom API 获取元素并在获取元素的属性之后

Element yourElement = DOM.getElementById(YOUR_TEXT_INPUT_ELEMENT);

 String the TextOfTheInput = yourElement.getAttribute("value");
于 2013-09-27T09:22:08.440 回答