开发者

jQuery .live() and IE

开发者 https://www.devze.com 2023-01-24 05:36 出处:网络
hey all, Im stumped. I have the following code..works fine in all browsers except IE (shocking...I know)

hey all, Im stumped. I have the following code..works fine in all browsers except IE (shocking...I know)

 $('#lbAvailableResources option').live('click', function() {
    if($('#ulResourcesAssigned').text() === 'No resources assigned')
         $('#ulResourcesAssigned').text('');

    //create a new listitem that will be added to the list of assigned resources
    $('<li>').val($(this).val()).text($(this).text()).appendTo('#ulResourcesAssigned'); });

the listbox (#lbAvailableResources) is loaded via an ajax call when the page loads.

Ive also tried the following: 1. I tried the delegate() method...no d开发者_如何学Cice 2. I tried livequery...no dice

any help would be greatly appreciated.


There are no events on the option element in IE.

The select element may be implemented as an OS widget, in which case you can forget getting any fine-grained mouse events on sub-parts of the control.

The change event on select is the only cross-browser-compatible way to be informed of a change of option. Note that keyboard navigation may also fire this event.

If what you want is a control that pops up a list of options and lets you add content to another element whenever any option is clicked, the select element is ill-suited. Try instead a pop-up div containing buttons.


Also, check your code and see if there are any places where you are using console.log(), or ending an array of values with a "," . These are two other instances that IE will not work while some other browsers will.


$('#lbAvailableResources option').die();

$('#lbAvailableResources option').live('click', function(event) {

  if ($('#ulResourcesAssigned').text() == 'No resources assigned') { //is absolute equality needed here?
    $('#ulResourcesAssigned').text('');
  } //i always use brackets, it makes for more readable code

  //create a new list item that will be added to the list of assigned resources
  $("li").val($(this).val()).text($(this).text()).appendTo('#ulResourcesAssigned'); //the "" are not needed
});

Give the above a try, I have no idea whether or not it works

0

精彩评论

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