如何从jQuery对象获取id,baseUri并将其用作字符串

时间:2022-12-07 21:11:57

I have a Jquery object like the example below

我有一个Jquery对象,如下例所示

[li#myid.item.fr-hide, prevObject: _.fn.init[1], context: a.link.pjaxload]0: li#myid.item.fr-hidecontext: a.link.pjaxloadlength: 1prevObject: _.fn.init[1]__proto__: _[0]

The object has an arrow pointing down and when i click the arrow , there are some other variable arrows namely 0: li#myid.item.fr-hide,accesskey etc. And when i click the 0, there are some more collections and among which is the baseUri.The baseUri contains a string uri with the part of the string which is myid. I want to compare and check that object all the time if part of that baseUri example

该对象有一个向下箭头,当我点击箭头时,还有一些其他变量箭头即0:li#myid.item.fr-hide,accesskey等。当我点击0时,还有一些更多的集合这是baseUri .baseUri包含一个字符串uri,字符串的一部分是myid。我想比较并检查该对象,如果该baseUri示例的一部分

//www.mydomain.com/myid?l=FR

contains myid . I tried everything possible but because my object is not a string i just count get it going/comparing

包含myid。我尝试了一切可能,但因为我的对象不是一个字符串,我只是计算得到它/比较

i tried.

   if(/myid/i.test($active.item.get(0).outerHTML){
}

It failed.

I tried

if(/myid/i.test($active.item.id.outerHTML){
}

It failed. I tried many more that i lost count. Note myid is an element that has id and its id is what i am after. But the id is also contain in the baseUri. Please any help would be appreciated.

它失败了。我尝试了很多,我失去了数。注意myid是一个具有id的元素,它的id就是我所追求的。但是id也包含在baseUri中。请任何帮助将不胜感激。

1 个解决方案

#1


0  

I finally get it going. active.item is a jQuery object. Below is what works for me

我终于明白了。 active.item是一个jQuery对象。以下是对我有用的

var $elementid = active.item.get(0).id;

if(active.item) {
   if(page.language() === 'FR' && /myid/i.test($elementid)){
    //My code
   }
}

Another issue i encounter was var $elementid = active.item.get(0).id; passed my element id value to $elementid. However

我遇到的另一个问题是var $ elementid = active.item.get(0).id;将我的元素id值传递给$ elementid。然而

if(page.language() === 'FR' && /myid/i.test($active.item.get(0).id)){
        //My code
       }

The above failed and always return false. When i log active.item.get(0).id on the console, it turns out it returns an object not my id . This i am not sure though , looking for a better explanation as well.

以上失败并始终返回false。当我在控制台上记录active.item.get(0).id时,结果是它返回的对象不是我的id。我不确定这一点,也在寻找更好的解释。

#1


0  

I finally get it going. active.item is a jQuery object. Below is what works for me

我终于明白了。 active.item是一个jQuery对象。以下是对我有用的

var $elementid = active.item.get(0).id;

if(active.item) {
   if(page.language() === 'FR' && /myid/i.test($elementid)){
    //My code
   }
}

Another issue i encounter was var $elementid = active.item.get(0).id; passed my element id value to $elementid. However

我遇到的另一个问题是var $ elementid = active.item.get(0).id;将我的元素id值传递给$ elementid。然而

if(page.language() === 'FR' && /myid/i.test($active.item.get(0).id)){
        //My code
       }

The above failed and always return false. When i log active.item.get(0).id on the console, it turns out it returns an object not my id . This i am not sure though , looking for a better explanation as well.

以上失败并始终返回false。当我在控制台上记录active.item.get(0).id时,结果是它返回的对象不是我的id。我不确定这一点,也在寻找更好的解释。