我有这个脚本:
<aui:script use="aui-node,aui-io-request,aui-base,event">
AUI().use('event', 'aui-node', 'aui-base', function (A) {
var inputObject = A.one('#_Tend_ApplicationMain_WAR_ETenderportlet_vrednost').on('keyup', function (event) {
alert("Hi you have performed On change Event and Thank You");
});
})
</aui:script>
为什么警报没有出现?
答案 0 :(得分:1)
您的代码有多个问题:
AUI().use(//...
属性<aui:script>
,则无需指定use
。aui-node
模块指定为use
属性的参数。inputObject
设置为等于on
方法的返回值。相反,您似乎想要var inputObject = A.one('#id');
。change
事件与keyup
事件不同,因此您的.on('change', function(event) { //...
或alert
消息声称它是onchange
事件不正确。A.one('#_Tend_ApplicationMain_WAR_ETenderportlet_vrednost')
无法找到该元素可能会出现问题(请查看浏览器日志以确定是否属实)。如果是,则您的元素可能具有部分生成的前缀,可以使用<portlet:namespace />
获得。如果你把所有这些放在一起:
<aui:script use="aui-node">
// possibly change the A.one() argument to '#<portlet:namespace />_Tend_ApplicationMain_WAR_ETenderportlet_vrednost'.
var inputObject = A.one('#_Tend_ApplicationMain_WAR_ETenderportlet_vrednost');
inputObject.on('keyup', function (event) {
alert("Hi you have performed On keyup Event and Thank You");
});
</aui:script>
这是一个可运行的例子:
YUI().use('aui-node', function(A) {
var inputObject = A.one('#_Tend_ApplicationMain_WAR_ETenderportlet_vrednost');
inputObject.on('keyup', function (event) {
alert("Hi you have performed On keyup Event and Thank You");
});
});
&#13;
<script src="https://cdn.rawgit.com/stiemannkj1/701826667a70997013605edcd37e92a6/raw/469fe1ae297e72a5a80eb9015003b7b04eac735e/alloy-ui-3.0.1_aui_aui-min.js"></script>
<link href="https://cdn.rawgit.com/stiemannkj1/90be22de7f48c729b443af14796d91d3/raw/a9f35ceedfac7fc0559b121bed105eaf80f10bf2/aui-css_css_bootstrap.min.css" rel="stylesheet"></link>
<input id="_Tend_ApplicationMain_WAR_ETenderportlet_vrednost" />
&#13;