Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
属性名为“的非选项元素的JQuery选择器”;精选;在IE8-IE9中_Jquery_Attributes_Selected - Fatal编程技术网

属性名为“的非选项元素的JQuery选择器”;精选;在IE8-IE9中

属性名为“的非选项元素的JQuery选择器”;精选;在IE8-IE9中,jquery,attributes,selected,Jquery,Attributes,Selected,我有一个html表格,里面有一些TRs,比如下面这些 <tr id="myId" class="aRandomClass" selected="TRUE">...</tr> <tr id="myId2" class="aRandomClass" selected="FALSE">...</tr> Firefox中的返回带有selected='TRUE'的TRs,但在MSIE 8-9中它什么也不返回。我猜问题在于属性“selected”不应该被TR

我有一个html表格,里面有一些TRs,比如下面这些

<tr id="myId" class="aRandomClass" selected="TRUE">...</tr>
<tr id="myId2" class="aRandomClass" selected="FALSE">...</tr>
Firefox中的返回带有selected='TRUE'的TRs,但在MSIE 8-9中它什么也不返回。我猜问题在于属性“selected”不应该被TRs使用,IE发现它无效或类似的东西。。但是下面的代码返回所选属性的值

var c=$("#" + tableId + " tr").first().attr('selected');
还有一点值得注意的是,这段代码与IE中的JQuery 1.4.2一起工作。通过升级到JQuery 1.8.3,它只在FF中工作

由于某些原因,我希望避免更改属性的名称

我想到的解决方案是一个循环“对于每个tr,如果选择了='true',在var a中添加tr”。
有更好的建议吗?

首先,您有重复的ID,应该是唯一的。其次,您可以使用
tr[selected=“true”]
选择行

您应该使用
选择的数据
,而不是该属性,这样您就有了一个有效的标记

我建议在jq 1.8.3中使用.prop(),但不确定它是否能帮助您:

var $trsSelected = $("#"+tableId).find('tr').filter(function(){return $(this).prop('selected')=='TRUE'});

var $trsNotSelected = $("#"+tableId).find('tr').filter(function(){return $(this).prop('selected')!='TRUE'});

为什么使用无效属性?您不能改为设置特定属性吗?当然,ID在上下文页面上必须是唯一的。不幸的是,该项目是由其他人编写的,我现在负责维护它。“selected”属性在java、xml、xslt和js中有几百个地方使用。更改它将需要很多..示例中重复的id仅为false。正如我上面所写的,您建议的选择器不起作用,这正是我所遇到的问题。此解决方案起作用,但它需要检查$(“#”+tableId).find('tr').filter(function(){return($(this).prop('selected')='TRUE')});所选属性包含字符串,应作为字符串而不是布尔值进行检查。
var $trsSelected = $("#"+tableId).find('tr').filter(function(){return $(this).prop('selected')=='TRUE'});

var $trsNotSelected = $("#"+tableId).find('tr').filter(function(){return $(this).prop('selected')!='TRUE'});