简体   繁体   中英

jQuery code works in IE9 but fails in FireFox?

I have written a jQuery code that works in IE9 but fails in FireFox.

The code is using jQuery UI to create a jQuery dialog with a set of items generated by a PHP page. the user will make a selection and the selected item should be added to a div container using a JS function.

Below is my code:

$(function() {
        $("#add-item-dialog").dialog({
            autoOpen: false,
                height: 600,
                width: 800,
                modal: true,

            close: function() {
                $( this ).dialog( "close" )
                    return false;
            }

        });
        $("#add-item")
            .button()
            .click(function() {
            $( "#add-item-dialog" ).load('add_item.php').dialog('open');
            });


        });
        function addItem(message){
            alert(message);
            $('#item_list').append(message + '<br>');
            $("#add-item-dialog").dialog("close")
                    return false;
        }       

The button for the function addItem is dynamically created with PHP as follows:

<input type="button" name="Add Item" value="'.$item_name.'" onClick="addItem(this.value)">

The expected output is an alert with the item name... then the item name is appended to the item_list div tag.

IE9 will append the text to the div, however, FireFox will only display the alert then do nothing.

What am i doing wrong?

Try to uninstall fire bug, it seems to be the problem while doing some research.

EDITED

Try this:

function addItem(message){
            var tmp_msg = message;
            alert(message);
            $('#item_list').append(tmp_msg + '<br>');
            $("#add-item-dialog").dialog("close")
                    return false;
        }

Maybe it's problem with .append() where it calls this.value instead of just getting the actual value.

As you wrote earlier alert() does work, so it's the .append() function that doesn't work, I think you need to get actual value from this.value and then pass it to .append() .

Let me know, how it goes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM