问题描述
这是我导入的js:<script type="text/javascript" src="../../js/join_care.js"></script>这是js里面的具体内容:var src1="http://localhost:8080/weibo/images/woyaoguanzhu.jpg";var src2="http://localhost:8080/weibo/images/quxiaoguanzhu.jpg";var src3="http://localhost:8080/weibo/images/woyaocanjia.jpg";var src4="http://localhost:8080/weibo/images/tuichuhuodong.jpg";var flag=true;var flag2=true;var img=null;var activity_id=null;function care(){img=jQuery("#img");activity_id=jQuery("#activity_id").val();if(flag){img.attr("src",src2);flag=false;jQuery.get("loveActivity.action?activity_id="+activity_id);alert("关注活动成功!"); }else{img.attr("src",src1);flag=true;jQuery.get("cancelCare.action?activity_id="+activity_id);alert("取消关注活动!"); }}function not_care(){img=jQuery("#img2");activity_id=jQuery("#activity_id").val();if(flag){img.attr("src",src1);flag=false;jQuery.get("cancelCare.action?activity_id="+activity_id);alert("取消关注活动!"); }else{img.attr("src",src2);flag=true;jQuery.get("loveActivity.action?activity_id="+activity_id);alert("关注活动成功!"); }}function join(){img=jQuery("#img3");activity_id=jQuery("#activity_id").val();if(flag2){img.attr("src",src4);flag2=false;//jQuery.get("loveActivity.action?activity_id="+activity_id);alert("参加活动成功!"); }else{img.attr("src",src3);flag2=true;//jQuery.get("cancelCare.action?activity_id="+activity_id);alert("退出活动成功!"); }}function not_join(){img=jQuery("#img4");activity_id=jQuery("#activity_id").val();if(flag2){img.attr("src",src3);flag2=false;//jQuery.get("cancelCare.action?activity_id="+activity_id);alert("退出活动成功!"); }else{img.attr("src",src4);flag2=true;//jQuery.get("loveActivity.action?activity_id="+activity_id);alert("参加活动成功!"); }}这是调用js里方法的代码: <input type="hidden" id="activity_id" value="${activity.activity_id}"/> <s:if test="#user_Activity==null"> <a href="javascript:care();"><img id="img" src="<%=basePath%>images/woyaoguanzhu.jpg" width="82" height="26"></a> </td> </s:if> <s:elseif test="#user_Activity.is_care==1"> <a href="javascript:not_care();"><img id="img2" src="<%=basePath%>images/quxiaoguanzhu.jpg" width="82" height="26"></a></td> </s:elseif> <s:else> <a href="javascript:care();"><img id="img" src="<%=basePath%>images/woyaoguanzhu.jpg" width="82" height="26"></a></td> </s:else>这是出现的错误:care is not defined
解决方案
应该是js文件没有正确的引入到页面中