开发者

jquery - selecting attr via variable

var attr = myopts.addAttributeFromChemSelect;
alert(ob.attr(attr));

is undefined

var attr = myopts.addAttributeFromChemSelect;
alert(attr);

is 'tip-ref'

var attr = myopts.addAttributeFromChemSelect;
alert(ob.attr('tip-ref');

is 'tip_0'

Can anyone explain to me why the first wont work.

regards

From Consol Log:

style="width: 100px; position: relative;" tip-ref="tip_0" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlSalutation" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlSalutation" onchange="SalutationChangeEvent_cphDoubleColumn_checkout_checkout_customer();"
tip-ref
undefined
tip_0
style="width: 170px; position: relative;" tip-ref="tip_4" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlGender" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlGender"
tip-ref
undefined
tip_4
style="width: 50px; position: relative;" tip-ref="tip_5" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlDOBDate" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlDOBDate"
tip-ref
undefined
tip_5
style="width: 100px; position: relative;" tip-ref="tip_6" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlDOBMonth" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlDOBMonth"
tip-ref
undefined
tip_6
style="width: 50px; position: relative;" tip-ref="tip_7" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlDOBYear" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlDOBYear"
tip-ref
undefined
tip_7
style="width: 170px; position: relative;" tip-ref="tip_12" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlOccupationStatus" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlOccupationStatus"
tip-ref
undefined
tip_12
style="width: 100px; position: relative;" tip-ref="tip_13" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlYearsWithEmployer" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlYearsWithEmployer"
tip-ref
undefined
tip_13
style="width: 100px; position: relative;" tip-ref="tip_14" name="ctl00$cphDoubleColumn$checkout$checkout_customer$ddlMonthsWithEmployer" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_customer_ddlMonthsWithEmployer"
tip-ref
undefined
tip_14
style="width: 100px; position: relative;" tip-ref="tip_22" name="ctl00$cphDoubleColumn$checkout$addressUC1$ddlYearsAtAddress" onchange="javascript:__CLDVcphDoubleColumn_checkout_lightboxProcessAddresses='cphDoubleColumn_checkout_addressUC1_ddlYearsAtAddress';Page_ValidationActive=false;setTimeout('__doPostBack(\'ctl00$cphDoubleColumn$checkout$addressUC1$ddlYearsAtAddress\',\'\')', 0)" class="chemSelectWrapper w_cphDoubleColumn_checkout_addressUC1_ddlYearsAtAddress"
tip-ref
undefined
tip_22
style="width: 100px; position: relative;" tip-ref="tip_23" name="ctl00$cphDoubleColumn$checkout$addressUC1$ddlMonthsAtAddress" onchange="javascript:__CLDVcphDoubleColumn_checkout_lightboxProcessAddresses='cphDoubleColumn_checkout_addressUC1_ddlMonthsAtAddress';Page_ValidationActive=false;setTimeout('__doPostBack(\'ctl00$cphDoubleColumn$checkout$addressUC1$ddlMonthsAtAddress\',\'\')', 0)" class="chemSelectWrapper w_cphDoubleColumn_checkout_addressUC1_ddlMonthsAtAddress"
tip-ref
undefined
tip_23
style="width: 170px; position: relative;" tip-ref="tip_24" name="ctl00$cphDoubleColumn$checkout$addressUC1$ddlResidentialStatus" class="chemSelectWrapper w_cphDoubleColumn_checkout_addressUC1_ddlResidentialStatus"
tip-ref
undefined
tip_24
style="width: 100px; position: relative;" tip-ref="tip_36" name="ctl00$cphDoubleColumn$checkout$checkout_BankDetails$ddlYearsWithBank" onchange="javascript:setTimeout('__doPostBack(\'ctl00$cphDoubleColumn$checkout$checkout_BankDetails$ddlYearsWithBank\',\'\')', 0)" class="chemSelectWrapper w_cphDoubleColumn_checkout_checkout_BankDetails_ddlYearsWithBank"
tip-ref
undefined
tip_36
style="width: 100px; position: relative;" tip-ref="tip_37" name="ctl00$cphDoubleColumn$checkout$checkout_BankDetails$ddlMonthsWithBank" class="chemSelectWrapper w_cphDouble开发者_Go百科Column_checkout_checkout_BankDetails_ddlMonthsWithBank"
tip-ref
undefined
tip_37

the code is in a plugin:

chemSelectboxRevert: function (opts, callbackFnk) {

            var myopts = $.extend({ keepSelected: true, addAttributeFromChemSelect : '' }, opts);

            var count = this.length;

            return this.each(function (i) {

                var ob = $(this);

                var attr = myopts.addAttributeFromChemSelect;

                console.log(getAttributes(ob));  console.log(attr); console.log(ob.attr(attr)); console.log(ob.attr('tip-ref'));

                var extraAttr = '';

                if (myopts.addAttributeFromChemSelect != '') {

                    var attr_extra = ob.attr(myopts.addAttributeFromChemSelect);

                    extraAttr = myopts.addAttributeFromChemSelect + '="' + attr_extra + '"';

                }
        ....
        ...
        ..


Actually it works: http://jsfiddle.net/fBLZR/


Same as Darin Dimitrov, my test worked. What is addAttributeFromChemSelect?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜