开发者

Need help to figure out why current code does not work with current latest (1.6.4) version of JQuery

开发者 https://www.devze.com 2023-04-08 17:19 出处:网络
Below is the code, the program is split into two main segments. One that performs operation on each Select element and the other

Below is the code, the program is split into two main segments. One that performs operation on each Select element and the other on all the option elements within this\each select and this one does not work as it should append a price "[+$00]" to each select option text value, bar the currently selected one. The piece of code that does not work is tagged. Worked fine with 1.5.1, 1.5.2 and does not work with all starting from 1.6

        // ===== CODE DOES NOT WORK FROM HERE WITH 1.6.4============
        $(this).find('option').each(function () {

            //$(this).append('<span></span>');

            var uov = parseInt($(this)开发者_StackOverflow中文版.attr('value')) || 0; //Unselected option value

            var uop; //Unselected Option Price


            for (d = 0; d <= data.length; d++) {


                if (data[d].partid == uov) {

                    uop = data[d].price;
                    break;
                }

            }

            //debugger;
            var pricediff = Math.abs(uop - sop);

            var xtext = $(this).text();





            if (xtext.match(/\✔/) != null) {

                var temp = xtext.replace(/✔/g, '');


                xtext = temp;
            }


            if (xtext.match(/\[.*\]/) != null) {
                var temp = xtext.split('[')[0];
                var temp2 = xtext.split(']')[1];

                xtext = temp2;
            }

            if (uov != 0) {

                if (pricediff != 0) {


                    var diff = '[' + (sop > uop ? '-' : '+') + '$' + pricediff + ']';


                    $(this).attr("text", diff + " " + xtext);
                }

                else {

                    $(this).attr("text", "  ✔  " + " " + xtext);


                }

            }

                  //=============== TO HERE ========================


Don't use:

$(this).attr('value')

to get the value of a form field. Use:

$(this).val()

This has caused many headaches with our client developers when we changed our framework's jQuery version.

--- Edit ---

You most certainly should not be trying to edit the text of an element with the attr() function as you have here:

 $(this).attr("text", diff + " " + xtext);

You should use:

 $(this).text(diff + " " + xtext);
0

精彩评论

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

关注公众号