How can I find if an id has a specific string ??? (Prototype)
Like http://bit.ly/ideYPm, i need change this:
function createPickers() {
$(document.body).select('input.datepicker').each( function(e) {
new Control.DatePicke开发者_开发知识库r(e, { 'locale': 'pt_BR'});
} );
}
Event.observe(window, 'load', createPickers);
To get "inputs" with "Data" (date in portuguese) string in id, like:
<input type="text" id="EntradaEquipamentoDataEntrada"></input>
You can use a wildcard like:
$$('input[id*="Data"]')
so your code would look more like:
function createPickers() {
$$('input[id*="Data"]').each( function(e) {
new Control.DatePicker(e, { 'locale': 'pt_BR'});
} );
}
Event.observe(window, 'load', createPickers);
<input type="text" id="EntradaEquipamentoDataEntrada"></input>
//Assuming datepicker has been assigned
var id = $('input.datepicker').readAttribute('id');
var checker = id.indexOf('Entrada');
//returns index of first match start position
//returns -1 if no matches found
use lastIndexOf()
to find last match
精彩评论