本文介绍了如何在jquery中动态获取id属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 下面是我的代码 < 输入 type = hidden id = cid value = < ;% = cid%> > < 输入 type = 隐藏 我d = email value = <% =用户%GT; > < 输入 类型 = 隐藏 id = gid 值 = <% = grid%> > < 输入 type = 隐藏 id = postid 值 = <% = postid%> > < input type = text value = <% = msg% > 名称 = comment id = 评论 > < 输入 类型 = 提交 value = submit id = <% = cid%> class = sub / > jquery函数是 $(。sub).click( function (e){ e.preventDefault(); var cid = $( #cid )VAL(); var comment = $( #comment )VAL(); var email = $( #mail )VAL(); var gid = $( #gid )VAL(); var postid = $( #postid )VAL(); var value = ' comment =' + comment + ' & cid =' + cid + ' & email =' + email + ' & gid =' + gid + ' & postid =' + postid; $ .ajax({ url: update.jsp, // type:post, data:value , cache: false ,成功: function (数据){ $( #comment_display)。html(data).slideDown(' fast'); } }); }); } 当我点击提交按钮时,id为<%= cid%>传递给$(。sub).click(函数(e)。我怎样才能动态获取id 解决方案 (。sub).click( function (e){ e.preventDefault(); var cid = ( #cid)。val(); var comment = ( #comment)。val(); var email = below is my code <input type="hidden" id="cid" value="<%=cid %>"> <input type="hidden" id="email" value="<%=user%> "><input type="hidden" id="gid" value="<%=grid %>"><input type="hidden" id="postid" value="<%=postid %>"><input type="text" value="<%=msg%>" name="comment" id="comment"><input type="submit" value="submit" id="<%=cid %>" class="sub"/>jquery function is $(.sub ).click(function(e) { e.preventDefault(); var cid=$("#cid").val(); var comment = $("#comment").val(); var email=$("#email").val(); var gid=$("#gid").val(); var postid=$("#postid").val(); var value ='comment='+comment+'&cid='+cid+'&email='+email+'&gid='+gid+'&postid='+postid; $.ajax({ url: "update.jsp", //type: "post", data: value, cache: false, success: function(data) { $("#comment_display").html(data).slideDown('fast'); } });});}when i click on the submit button the id is<%=cid%> is pass to the $(.sub ).click(function(e). how can i get id dynamically 解决方案 (.sub ).click(function(e) { e.preventDefault(); var cid=("#cid").val(); var comment =("#comment").val(); var email= 这篇关于如何在jquery中动态获取id属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 10:28