English 中文(简体)
原型框架/从按钮调用
原标题:
  • 时间:2008-12-15 19:02:28
  •  标签:
I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.

我认为这很直观,但我得到的结果与我阅读的教程不同。我在一个HTML页面上有一个按钮,该按钮调用脚本标签中的函数。我还有一个对prototype.js文件的引用,我甚至还没有开始实施。如果我保留页面上的该引用,则我的按钮onclick事件中的函数调用将不起作用。以下是从按钮onclick事件中调用的内容。

I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.

callIt = function(){

alert( It worked! );
}

</script>
I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.
I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.I'm sorry, but you haven't provided any text to be translated. Please provide the text you want to translate into Chinese.
最佳回答

几件事情:首先,请确保您的HTML有效。将其通过验证器运行在 http://validator.wc.org

接下来,一旦您确定您的页面是有效的,请将prototype.js库作为页面上的第一个脚本引用添加进去:

<script type="text/javascript" src="prototype.js"></script>

请注意,我没有像这样关闭它<script ... />脚本块需要有显式的结束标记(至少在XHTML 1.0 Transitional中)

现在,回答你的问题,我不太确定你在问什么,但是如果你想使用Prototype将callIt方法附加到你的按钮的onclick处理程序上,那么可以这样做:

Event.observe(window,  load , function() {
    Event.observe( button_id ,  click , callIt);  
});

将此代码放置在页面的<head>元素下的原型脚本引用之后的<script>标签中。这将在DOM加载后执行,并且页面上存在按钮时执行。

希望这有所帮助。

问题回答

那个起作用了。我只是困惑为什么我一直在使用的例子都没有做到这一点。

谢谢!





相关问题
热门标签