教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jQuery动态选择器的小例子

jQuery动态选择器的小例子

发布时间:2016-01-02   编辑:jiaochengji.com
本文介绍了一个jQuery动态选择器的例子,有需要的朋友参考下。

在使用struts2时,经常在页面中使用<s:iterator value="list"></s:iterator>,此时若需要用jquery对这标签之间的其他标签进行操作的话,会因为动态的id而找不到目标标签,通常的做法是$("#"+id),此做法大多数情况下不可行,最终还是改用js自身的方法来操作。

具体方法:
 

复制代码 代码示例:
<s:iterator value="peList"> 
   <tr class="s1" title="点击修改信息" style="height: 20px;" align="center" onmouseover="changeColor(this);" onmouseout="backColor(this);"> 
     <td width="12%"><input type="checkbox" name=personIDs" value="${personID }"/></td> 
     <td width="30%" id="${personID }" onclick="toUpdate(this.id);"> 
<s:property value="userName"/> 
     </td> 
     <td width="30%" id="${personID }"> 
           <s:property value="personName"/> 
     </td> 
     <td width="28%"> 
           <input type="button" id="${personID }" style="color: red;background-color: yellow;" onclick="toPowerSet(this,this.id);" value="${powerSet }"/> 
     </td></tr> 
</s:iterator>

如果要修改第四个<td>的内容,做法如下:
将自身对象和id传给js方法进行操作,这比jQuery选择器来的可靠。
 

复制代码 代码示例:
function toPowerSet(a,id){ 
powerdao.dwrPowerSet(id,function(result){ 
    if(result != "empyt"){ 
        if(result == "admin"){ 
a.value = "管理员"; 
        } 
        if(result == "person"){ 
a.value = "操作员"; 
        } 
    } 
   }); 

您可能感兴趣的文章:
jquery 获取对象的方法以及jquery 选择器的使用
jQuery学习笔记之jQuery选择器的使用
jQuery选择器总结
jQuery基本过滤选择器使用介绍
详解强大的jQuery选择器之基本选择器、层次选择器
Jquery实战_读书笔记2 选择器
有关jquery一些选择器的用法小结
css/jquery实现移除HTML中最后和第一个元素的间距(margin)
jquery选择器(常用选择器说明)
jQuery动态选择器的小例子

关键词: Jquery选择器  选择器   
[关闭]
~ ~