I have this button:
<button id="check_button" name ="check_button" type="button" onclick="setLocation('...')">
<span>check</span>
</button>
Now I know I can access it using $('check_button')
for example. Is there a way to set the setlocation
parameter with Prototype?
I have this button:
<button id="check_button" name ="check_button" type="button" onclick="setLocation('...')">
<span>check</span>
</button>
Now I know I can access it using $('check_button')
for example. Is there a way to set the setlocation
parameter with Prototype?
2 Answers
Reset to default 3function doButtonClick(event, element) {
console.log('event');
console.log('element');
// here, `element` is a reference to the button you clicked.
var elementId = element.identify();
// I'm not sure what setLocation takes in as a parameter, but...
setLocation(elementId);
}
$('check_button').on('click', 'button', doButtonClick);
Here are the docs for the element.on
: http://api.prototypejs/dom/Element/prototype/on/
Which is really just a quick way of creating a new Event.Handler
: http://api.prototypejs/dom/Event/on/
For sure check out that second doc link - super useful stuff.
Yes,
$('check_button').observe('click',this.setLocation.bind(this,'...'));
setLocation: function(param)
{
alert(param);
}
In this way the param will be always what you pass. " bind " ia a vary powerfull method which holds that ability.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744300245a4567464.html
评论列表(0条)