雅虎 UI 自定义按钮
我有一个通过 HTML 标记定义的 YUI 按钮。我设法正确地加载和“蒙皮”。
问题是自定义点击事件。我尝试了多种方法,所有这些方法都将自定义函数链接到“单击”事件,但无论我采用哪种方式,它总是在页面加载时触发,然后单击时不会触发。我似乎无法让它“等待”用户点击。在他第一次约会时,它就像处女一样。
代码如下....
<script type="text/javascript">
YAHOO.util.Event.onContentReady("submitbutton", onButtonReadySubmit);
YAHOO.util.Event.onContentReady("editbutton",onButtonReadyEdit);
var myTabs = new YAHOO.widget.TabView("demo");
function editDoc(sBaseRef, sUNID) {
var sNewURL = sBaseRef + "/0/" + sUNID + "?EditDocument";
alert("Going to : " + sNewURL);
window.location.href=sNewURL;
}
function onButtonReadySubmit() {
var oSubmitButton = new YAHOO.widget.Button("submitbutton");
}
function onButtonReadyEdit() {
var oEditButton = new YAHOO.widget.Button("editbutton");
YAHOO.util.Event.addListener("editbutton", 'click', editDoc('a URL path goes here' , 'A PageKey goes here'));
}
I have a YUI button defined through HTML markup. I managed to get it loaded and "skinned" properly.
The problem is a custom click event. I have tried a number of approaches all of which links the custom function to the 'click' event, but no matter which way I do it, it ALWAYS triggers upon page loading and then it doesn't fire when clicked. I can't seem to get it to "wait" for a user to click. It just shoots like a virgin on his first date.
Code below....
<script type="text/javascript">
YAHOO.util.Event.onContentReady("submitbutton", onButtonReadySubmit);
YAHOO.util.Event.onContentReady("editbutton",onButtonReadyEdit);
var myTabs = new YAHOO.widget.TabView("demo");
function editDoc(sBaseRef, sUNID) {
var sNewURL = sBaseRef + "/0/" + sUNID + "?EditDocument";
alert("Going to : " + sNewURL);
window.location.href=sNewURL;
}
function onButtonReadySubmit() {
var oSubmitButton = new YAHOO.widget.Button("submitbutton");
}
function onButtonReadyEdit() {
var oEditButton = new YAHOO.widget.Button("editbutton");
YAHOO.util.Event.addListener("editbutton", 'click', editDoc('a URL path goes here' , 'A PageKey goes here'));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
YUI Button 发布您在 YUI Button 实例上订阅的自己的单击事件,而不是使用 YAHOO.util.Event.addListener。 YUI Button 登陆页面对此进行了详细描述: http://developer.yahoo.com /yui/button/#handlingevents。
YUI Button publishes its own click event that you subscribe to on the YUI Button instance, rather than using YAHOO.util.Event.addListener. This is described in detail on the YUI Button landing page: http://developer.yahoo.com/yui/button/#handlingevents.
你的问题是第三个参数。那应该是对函数的引用。您的代码中发生的情况是,第 3 个参数是一个函数,在创建侦听器时调用该函数,并且不返回任何内容。
您拥有:
您想要的只是:
但是,您还希望将“此处为 URL 路径”和“此处为 PageKey”传递给点击时的函数 -时间。为此,请使用 addListener() 的可选第四个参数 - 要传递给函数的对象。
请参阅 http://developer.yahoo.com/yui/docs /YAHOO.util.Event.html#method_addListener 了解更多。
正如 Todd 提到的,您也可以将其作为 YUI 按钮创建的一部分来执行 - 但同样存在函数与函数引用的问题。
Your problem is the 3rd argument. That should be a reference to function. What happens in your code is that the 3 argument is a function that is called as the listener is being created, and returns nothing.
You have:
Simply what you want is:
However, you also want to pass 'a URL path goes here' and 'A PageKey goes here' to the function at click-time. To do this, use the optional fourth argument to addListener() - an object to pass to the function.
See http://developer.yahoo.com/yui/docs/YAHOO.util.Event.html#method_addListener for more.
As Todd mentions, you can also do this as part of the YUI Button creation - but the same issues of function versus function references apply.