开发者

How can I find if an id has a specific string ??? (Prototype)

开发者 https://www.devze.com 2023-02-08 09:16 出处:网络
Like http://bit.ly/ideYPm, i need change this: function createPickers() { $(document.body).select(\'input.datepicker\').each( function(e) {

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

0

精彩评论

暂无评论...
验证码 换一张
取 消