用Jquery在JS中取jsp页面的中的元素
2014-04-22 11:04
176 查看
这篇文章是我在修改项目需求时遇到的问题,最后找到的解决方法,分享给大家
先给大家看看前台的页面代码
<table class="border_tab">
<tr>
<td width="50%" class="content_td">
<div class="content_title">已选套餐<input type="button" class="btn1" value="选择" onclick="javascript:spkg();" /></div>
<div class="clear"></div>
<table class="edit_list_tab" id="pkgtable">
<tr class="head">
<th>套餐名称</th>
<th>折扣</th>
<th>操作</th>
</tr>
<s:iterator value="itempkgex">
<tr class="row" pkgid="<s:property value="id"/>" pkgname="<s:property value="package_name" escapeHtml="false"/>">
<td><s:property value="package_name" escapeHtml="false"/></td>
<td><s:property value="discount"/> </td>
<td><span class="link_a"><a href='###' atype='delBtn'>删除</a></span></td>
</tr>
</s:iterator>
</table>
</td>
<td width="50%" class="content_td">
<div class="content_title">已选组合项目(<input type="text" id="group_count" name="record.group_count" value="<s:property value="record.group_count"/>" style="width:25px;background-color:transparent;text-align:center" readonly="readonly"/>)<input type="button" class="btn1"
value="选择" onclick="javascript:sitem();"/><s:property value="record.group_count"/></div>
<div class="clear"></div>
<table class="edit_list_tab" id="itemtable">
<tr class="head">
<th>所属套餐</th>
<th>组合项目名称</th>
<th>单价</th>
<th>折扣</th>
<th>现价</th>
<th>操作</th>
</tr>
<s:iterator value="itemgroupex">
<tr class="row" rowtype='groupCount' pkgid="<s:property value="package_id"/>" dj="<s:property value="amount_receivable"/>" itemid="<s:property value="id"/>" itemname="<s:property value="group_name" escapeHtml="false"/>" >
<td>
<input type='hidden' value="<s:property value="package_id"/>" name='sitempkg'/>
<s:property value="package_name" escapeHtml="false"/>
</td>
<td>
<input type='hidden' value="<s:property value="id"/>" name='sitemgroup' id='sitemgroupids'/>
【 <s:property value="deptex_name" escapeHtml="false"/>】 <s:property value="group_name" escapeHtml="false"/>
<s:if test="is_add_item eq 1">
<font class="red">
(加)
</font>
</s:if>
</td>
<td><s:property value="amount_receivable"/><input type="hidden" name="amount_receivable" value="<s:property value="amount_receivable"/>"/> </td>
<s:if test="is_discount==\"0\"">
<td><input type="hidden" name="discount" value="<s:property value="discount"/>"/><s:property value="discount"/></td>
<td><input type="hidden" name="amount_paid" is_discount="<s:property value="is_discount"/>" value="<s:property value="amount_paid"/>"/><s:property value="amount_paid"/></td>
</s:if>
<s:else>
<td><input class="inp" maxlength="10" type="text" name="discount" value="<s:property value="discount"/>"/></td>
<td><input class="inp" maxlength="10" type="text" is_discount="<s:property value="is_discount"/>" name="amount_paid" value="<s:property value="amount_paid"/>"/></td>
</s:else>
<td><span class="link_a"><a href='###' atype='delBtn'>删除</a></span></td>
</tr>
</s:iterator>
</table>
</td>
</tr>
</table>
在给大家看看js怎么写的
$("#itemtable").on("click","a[atype='delBtn']",function(){
//$(this).closest("tr").remove();
thisvalues+=$(this).closest("tr").find('td').eq(1).find('input').val()+",";
$(this).closest("tr").css("text-decoration","line-through").css("color","red");
//$("#hiddenItemIds").attr("value",thisvalues);
$(this).closest("tr").find('td').eq(3).find('input').removeAttr("name");
$(this).closest("tr").removeAttr("itemname").removeAttr("itemid").removeAttr("pkgid");
$(this).closest("tr").find('td').eq(1).find('input').removeAttr("name");
$(this).closest("tr").find('td').eq(2).find('input').removeAttr("name");
$(this).closest("tr").find('td').eq(3).find('input').removeAttr("name");
$(this).closest("tr").find('td').eq(4).find('input').val("0.00");
$(this).closest("tr").find('td').eq(4).find("input[name='amount_paid']").removeAttr("name");
$(this).closest("tr").find('td').eq(5).find("input[name='sitempkg']").removeAttr("name");
$(this).closest("tr").find('td').eq(5).find("input[name='sitemgroup']").removeAttr("name").removeAttr("id");
$(this).closest("tr").removeClass("row");
tjyj();
});
可以根据上边的方法解决
先给大家看看前台的页面代码
<table class="border_tab">
<tr>
<td width="50%" class="content_td">
<div class="content_title">已选套餐<input type="button" class="btn1" value="选择" onclick="javascript:spkg();" /></div>
<div class="clear"></div>
<table class="edit_list_tab" id="pkgtable">
<tr class="head">
<th>套餐名称</th>
<th>折扣</th>
<th>操作</th>
</tr>
<s:iterator value="itempkgex">
<tr class="row" pkgid="<s:property value="id"/>" pkgname="<s:property value="package_name" escapeHtml="false"/>">
<td><s:property value="package_name" escapeHtml="false"/></td>
<td><s:property value="discount"/> </td>
<td><span class="link_a"><a href='###' atype='delBtn'>删除</a></span></td>
</tr>
</s:iterator>
</table>
</td>
<td width="50%" class="content_td">
<div class="content_title">已选组合项目(<input type="text" id="group_count" name="record.group_count" value="<s:property value="record.group_count"/>" style="width:25px;background-color:transparent;text-align:center" readonly="readonly"/>)<input type="button" class="btn1"
value="选择" onclick="javascript:sitem();"/><s:property value="record.group_count"/></div>
<div class="clear"></div>
<table class="edit_list_tab" id="itemtable">
<tr class="head">
<th>所属套餐</th>
<th>组合项目名称</th>
<th>单价</th>
<th>折扣</th>
<th>现价</th>
<th>操作</th>
</tr>
<s:iterator value="itemgroupex">
<tr class="row" rowtype='groupCount' pkgid="<s:property value="package_id"/>" dj="<s:property value="amount_receivable"/>" itemid="<s:property value="id"/>" itemname="<s:property value="group_name" escapeHtml="false"/>" >
<td>
<input type='hidden' value="<s:property value="package_id"/>" name='sitempkg'/>
<s:property value="package_name" escapeHtml="false"/>
</td>
<td>
<input type='hidden' value="<s:property value="id"/>" name='sitemgroup' id='sitemgroupids'/>
【 <s:property value="deptex_name" escapeHtml="false"/>】 <s:property value="group_name" escapeHtml="false"/>
<s:if test="is_add_item eq 1">
<font class="red">
(加)
</font>
</s:if>
</td>
<td><s:property value="amount_receivable"/><input type="hidden" name="amount_receivable" value="<s:property value="amount_receivable"/>"/> </td>
<s:if test="is_discount==\"0\"">
<td><input type="hidden" name="discount" value="<s:property value="discount"/>"/><s:property value="discount"/></td>
<td><input type="hidden" name="amount_paid" is_discount="<s:property value="is_discount"/>" value="<s:property value="amount_paid"/>"/><s:property value="amount_paid"/></td>
</s:if>
<s:else>
<td><input class="inp" maxlength="10" type="text" name="discount" value="<s:property value="discount"/>"/></td>
<td><input class="inp" maxlength="10" type="text" is_discount="<s:property value="is_discount"/>" name="amount_paid" value="<s:property value="amount_paid"/>"/></td>
</s:else>
<td><span class="link_a"><a href='###' atype='delBtn'>删除</a></span></td>
</tr>
</s:iterator>
</table>
</td>
</tr>
</table>
在给大家看看js怎么写的
$("#itemtable").on("click","a[atype='delBtn']",function(){
//$(this).closest("tr").remove();
thisvalues+=$(this).closest("tr").find('td').eq(1).find('input').val()+",";
$(this).closest("tr").css("text-decoration","line-through").css("color","red");
//$("#hiddenItemIds").attr("value",thisvalues);
$(this).closest("tr").find('td').eq(3).find('input').removeAttr("name");
$(this).closest("tr").removeAttr("itemname").removeAttr("itemid").removeAttr("pkgid");
$(this).closest("tr").find('td').eq(1).find('input').removeAttr("name");
$(this).closest("tr").find('td').eq(2).find('input').removeAttr("name");
$(this).closest("tr").find('td').eq(3).find('input').removeAttr("name");
$(this).closest("tr").find('td').eq(4).find('input').val("0.00");
$(this).closest("tr").find('td').eq(4).find("input[name='amount_paid']").removeAttr("name");
$(this).closest("tr").find('td').eq(5).find("input[name='sitempkg']").removeAttr("name");
$(this).closest("tr").find('td').eq(5).find("input[name='sitemgroup']").removeAttr("name").removeAttr("id");
$(this).closest("tr").removeClass("row");
tjyj();
});
可以根据上边的方法解决
相关文章推荐
- js及jquery获取页面和元素的宽高
- 在jsp页面导入jquery多个js文件
- 对html或jsp文章列表页面进行js分页,结合使用apache的url Rewrite和jquery
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参(selected的值和页面其它元素的值)以及js的select
- JS和JQUERY获取页面大小,滚动条位置,元素位置(示例代码)
- 超棒的悬浮层式的页面元素注解jQuery插件 - Chardin.js
- js与jquery获得页面大小、滚动条位置、元素位置
- js及jquery获取页面和元素的宽高
- fm.revealator.jquery.js 滚动页面,控制页面元素逐一出来
- 页面滚动图片等元素动态加载插件jquery.scrollLoading.js
- js与jquery获得页面大小、滚动条位置、元素位置
- JS与JQUERY获取页面大小、滚动条位置、元素位置
- 【HTML/JS,JQuery】JQuery操作iframe父页面与子页面的元素与方法
- JS与JQUERY获取页面大小、滚动条位置、元素位置
- JS Jquery 遍历,筛选页面元素 自动完成(实现代码)
- 超棒的悬浮层式的页面元素注解jQuery插件 - Chardin.js
- 获取页面中被选中元素的 JS原生方法 与 jQuery方法 分析
- js与jquery获得页面大小、滚动条位置、元素位置
- JS与JQUERY获取页面大小、滚动条位置、元素位置
- aos.js超赞页面滚动元素动画jQuery动画库