开发者

JQuery doesnot support custom attribute in IE*?

In html I have on table like this:

<table for="availableTimeRanges"></table>

then I user jquery to find the table

var table = $("table[for='availableTimeRanges']");

In firefox and chrome, this works,can return the table, but in IE开发者_JS百科8, nothing return Then i run below code in IE8, found the attribute value is empty:

$.each($("table"), function(i,n){
        alert($(n).attr("for")

});

what's the reason


To add to what Šime Vidas said, Try Changing the name from for to something else like forparam, htmlfor, etc. (You can not use for with a table its for labels that are for an input)

$(function () {

        $('table[forparam=availableTimeRanges]').each(function () {
            alert($(this).attr('forparam'));
        });

    });


You better use class names they are supported everywhere

<table class="for_availableTimeRanges"></table>

and

$('.for_availableTimeRanges')


In think you should try wrapping your code in $(function(){...});

$(function(){
   $.each($("table"), function(i,n){
        alert($(n).attr("for")
   });
});


<table data-ranges="availableTimeRanges"> </table>

var ranges = {
  set : function (options){
     options = options || [];
     //loop and set ranges
  },
  get : function(){
     $("table [data-ranges='availableTimeRanges']").each(function(){
         alert($(this).data("ranges"));
     }); 
  }
};
ranges.get // calls get method
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜