2012-06-29 8 views
19

का उपयोग कर मैंने किसी चीज़कैसे चर

var Messages = { 
'fullName' : 'Tell us your cool name dude..! e.g. Yousuf Iqbal', 
'userName' : 'Choose a catchy username. Remember! It should be available :)', 
'password' : 'Choose a top secret password with special chars, numbers and alphabets', 
'rePassword' : 'Retype the password you just typed. But, don\'t try to copy!', 
'bYear' : 'Tell the year, in which this bomb blasted' 
}; 

और एक चर राशि वस्तु संपत्ति का उपयोग करने की ..

var attribute = $('#userinfo form input').attr('name'); 

अब मैं संदेश इस तरह इस चर का उपयोग कर संपत्ति वस्तु का चयन करना चाहते ..

var message = Messages.attribute; 

लेकिन यह काम नहीं कर रहा है .. और निम्नलिखित भी कोशिश की है ..

var message = Messages+'.'+attribute; 

उत्तर

42

वर्गाकार कोष्ठक:

message = Messages[ attribute ]; 
+2

................. :) –

5
var message = Messages[attribute]; 
+0

........... ........ :) –