javascript - Java:未调用文本字段onkeydown上if-else条件下的Javascript方法
问题描述
我mehtod1()
在 html 中的检票口组件上调用 javascript 方法。我必须根据下拉列表中的选定选项调用该方法。
<select wicket:id="user.type" id="user.type">
<option>dummy</option>
</select>
<input type="text" wicket:id="identity" id="identity"
onkeydown="if(document.getElementById('user.type').options[document.getElementById('user.type').selectedIndex].value=='52')return method1('abc');
else return method1('xyz');"/>
但是 if-else 条件不起作用。如果我删除此条件并仅调用它,method1()
则它可以正常工作。我认为getElementById
不工作,这就是为什么条件被跳过并且method1()
根本没有被调用的原因。
爪哇:
identityField = (TextField<String>) new TextField<String>("identity", new Model()).add(new ErrorIndicator());
identityField.setOutputMarkupId(true);
userTypeDropDown = (LocalizableLookupDropDownChoice<String>) new LocalizableLookupDropDownChoice<String>("user.type", String.class, "abc", this,
false, true, mobBasePage.getLocale()).setNullValid(true).add(new ErrorIndicator());
userTypeDropDown.setDefaultModel(new Model<String>());
userTypeDropDown.setRequired(true);
userTypeDropDown.setOutputMarkupId(true);
userTypeDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
...
}
}
我无法删除setOutputMarkupId(true)
,因为我还需要在组件上调用 ajax。
解决方案
userTypeDropDown.setMarkupId("user.type");
添加这个..这将解决您的问题。
推荐阅读
- typescript - Angular 6 项目:“task.downloadURL()”不见了?
- java - MockMvc REST 控制器 - 始终返回空主体
- ruby-on-rails - Rails gem 和 bundle 的问题
- mysql - 无法在 Netbeans 8.2 中启动/连接到 MySQL 8.0
- jquery - 使用引导程序和 python 路由导航选项卡
- c# - 使用 FillWeight 后如何获取 datagridview 列的绝对宽度?
- winforms - 如何对齐各个列中的输入数据?
- python - How to add leading 0's to different values in same column in pandas?
- node.js - 使用 jwt 和 nodejs 的密码重置链接
- c++ - 使用 scanf() 具有不同数据类型的多个输入