如何使用jquery在下面的html中找到name属性

how to find the name attribute is present or not in below html using jquery

本文关键字:name 属性 html 何使用 jquery 在下面      更新时间:2023-09-26

HTML详细信息:

<iframe width="465" height="285" frameborder="0" allowfullscreen="true" src="http://www.youtube.com/embed/7KS8KGGTpkI?wmode=transparent&amp;vq=hd720"></iframe> 
<p>aksfasjfksalfsfsjkf</p>
<h3>asfasdfasdfasfas</h3>
<iframe width="465" height="285" frameborder="0" allowfullscreen="true" src="http://www.youtube.com/embed/7KS8KGGTpkI?wmode=transparent&amp;vq=hd720" name="test1"></iframe>

我需要在iframe中找到name属性。我必须根据标签中是否存在name属性来对iframe标签进行分组。

HI friends在html上面,我想在iframe标签中添加name属性。如果iframe标记不包含name属性。

这就是您想要的吗?

var t =  $("iframe[name]").attr("name");

它返回iframe的"name"属性,该属性具有:http://jsfiddle.net/rb8vE/

  var t =  $( "iframe[name='test1']" ); // is this what you wanted?

使用jQuery,使用具有该属性的name属性旁边的拨号会变得更容易。

var iframeWithNameAttr = $("iframe[name]") ;// to search all iframe with name attribute
var iframeWithoutNameAttr = $("iframe").not("[name]") ;// to search all iframe without name attribute
var iframeWithFooNameAttr = $("iframe[name=foo]") ;// to seach all iframe with name equals to foo

有关jQuery属性选择器的更多信息。。。http://api.jquery.com/category/selectors/attribute-selectors/

编辑:

如果你想在没有标签的iframe中添加标签名称,你可以使用下面的表单:

var iframesWithoutName = $("iframe",t).not("[name]");
$(iframesWithoutName).attr("name", "insert the name here!");

下面是jsFiddle与您的示例工作。。。

http://jsfiddle.net/Castrolol/FNfB8/