我有一个dijit / form /按钮添加到dijit / layout / ContentPane。然后将dijit / layout / ContentPane放在dijit / form / DropDownButton中。当我点击dijit / form /按钮时,它不会第一次触发。对于这个例子,我只是按下按钮生成一个警告框,其值输入ValidationTextBox。我在其他论坛上看到过关于这个主题的一些讨论,暗示onMouseDown事件或焦点事件正在淘汰第一个onClick事件。测试这些事件何时加载的最佳方法是什么,或者我只是在dijit / form / button的代码中遗漏了什么?谢谢你看看。
dojoConfig = {
parseOnLoad: true
}
require(["dijit/form/DropDownButton", "dijit/MenuItem", "dijit/layout/ContentPane", "dijit/form/ValidationTextBox", "dijit/form/Button"],
function(DropDownButton, DropDownMenu, ContentPane, ValidationTextBox, Button) {
var parcelsearchCP = new ContentPane({
id: 'parcelsearchCP',
tabindex: 0
});
var parcelsearchInput = new ValidationTextBox({
title: "Enter Parcel ID",
name: "parcelvalue",
id: "parcelsearchInput",
placeholder: "<enter 8 digits>",
regExp: "^[0-9]*$"
});
var searchBtn = new Button({
//iconClass: "mySearchIcon",
name: "searchme",
label: "click me"
});
searchBtn.startup();
dojo.place("<div>Enter Parcel ID: </div>", parcelsearchCP.containerNode);
dojo.place(parcelsearchInput.domNode, parcelsearchCP.containerNode);
dojo.place(searchBtn.domNode, parcelsearchCP.containerNode);
var button = new DropDownButton({
label: "hello!",
name: "programmatic2",
dropDown: parcelsearchCP,
id: "progButton"
}, "dropDownButtonContainer").startup();
dojo.connect(searchBtn, "onClick", function() {
var boxentry = dijit.byId("parcelsearchInput");
if (boxentry.value !== "" || parcelsearchInput.isValid() === true) {
alert(boxentry.value);
} else {
alert("Please enter a valid 8 digit number and re-submit.");
}
});
});
<link href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<body class="claro">
<div id="dropDownButtonContainer"></div>
</body>
答案 0 :(得分:0)
事实证明,我所要做的就是将事件从“onClick”更改为“onMouseDown”,并在按钮连接语句中添加searchBtn.focus()。这似乎成功了。谢谢你的时间!