获取div中的name属性的值 [急],该怎么处理
获取div中的name属性的值 [急]
我有多个div , 想要获取name里面的文本并遍历使用
class 为 product_storyList_content_left
但是我用的上述方法只能获得一个, 怎么获得多个? 求解. 在线等
------解决方案--------------------
$(".product_storyList_content_left") 得到的是多个div,需要遍历他们
------解决方案--------------------
------解决方案--------------------
var name=$(".product_storyList_content_left").attr("name");
我有多个div , 想要获取name里面的文本并遍历使用
class 为 product_storyList_content_left
但是我用的上述方法只能获得一个, 怎么获得多个? 求解. 在线等
------解决方案--------------------
$(".product_storyList_content_left") 得到的是多个div,需要遍历他们
------解决方案--------------------
$(".product_storyList_content_left").each(function(){
alert($(this).attr("name"));
});
------解决方案--------------------
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
var name=[];
$(".product_storyList_content_left").each(function(){
name.push(this.name);
});
alert(name);
});
</script>
<input type="button" name="aaaaaaa" class="product_storyList_content_left" />
<input type="button" name="bbbbbbb" class="product_storyList_content_left" />
<input type="button" name="ccccccc" class="product_storyList_content_left" />
<input type="button" name="ddddddd" class="product_storyList_content_left" />