边看边学边记。
1.有时候某些常用方法在jsp会失效,没琢磨出失效规律,只能多备一些失效时替换成功的方式。
查询条件返回设定失效时:
$("#approvalitemsSeq").attr("value",'${seq}'); Attribute ->jsp
select重加载change无效时:
<select id="selectStatus" name="isArchived"> <option value="3"> 未同步 </option> <option value="2"> 待同步 </option> </select>
$("#selectStatus").change(function(){ //alert($(this).children('option:selected').val()); var status=$(this).children('option:selected').val();//这就是selected的值 url = "../archiveManagement/archiveAction!queryMetadata.action?status="+status; window.location.href(url); })
jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selected").text(); //获取Select选择的Text 2. var checkValue=jQuery("#select_id").val(); //获取Select选择的option Value 3. var checkIndex=jQuery("#select_id ").get(0).selectedIndex; //获取Select选择的索引值 4. var maxIndex=jQuery("#select_id option:last").attr("index"); //获取Select最大的索引值 jQuery添加/删除Select的Option项: 1. jQuery("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项) 2. jQuery("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置) 3. jQuery("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个) 4. jQuery("#select_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个) 5. jQuery("#select_id option[value='3']").remove(); //删除Select中Value='3'的Option 6. jQuery("#select_id option[text='4']").remove(); //删除Select中Text='4'的Option 内容清空: jQuery("#select_id").empty();
2.关于检测浏览器的方法:
OAT.Dom = { isIE:function() { return (document.attachEvent && !document.addEventListener ? true : false); },
看的颇为不解,查阅API时豁然开朗,API:
使用addEventListener(事件类型,监听器,将useCapture)
不支持IE浏览器,它使用的attachEvent()来代替。
扩展:
<script>
if(!+[1,])alert("这是ie浏览器");
else alert("这不是ie浏览器");
</script>
其实有很多判断的方法,大都是根据浏览器的特性来的。
比如库prototype的方法是:
!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) 。就是根据ie支持window.attachEvent添加侦听事件,非ie用window.addEventListener添加侦听事件来判断的。
navigator.userAgent.indexOf('Opera') === -1是因为opara浏览器能伪装成ie.如果!!(window.attachEvent )为真,就是ie;反之,如果!window.addEventListener为真,也可以判断为ie.Ext使用的是!"1"[0],他利用IE无法使用数组下标访问字符串的特性来判断。在ie8下好像有问题。
在!+[1,]还未被发现前,判断ie最短的表达式是 !+"\v1".它利用的是ie不支持垂直制表符的特性。
以前还有一个常用方法是document.all,由于opera浏览器能伪装成ie。可以这样写:!!(document.all && navigator.userAgent.indexOf('Opera') === -1).
还有很多,先记这几条,便于工作时查阅。
1.+[1,] 2.!+"\v1" 3.!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) 4.!!(!window.addEventListener&& navigator.userAgent.indexOf('Opera') === -1) 5.!!(document.all && navigator.userAgent.indexOf('Opera') === -1)
3。对于调用他人模块的事项弹窗选择, 我只配url和接受返回值.
他人的模块js :
/***/ function submitForm() { var itemNo = jQuery("input[name='ids']:checked"); if (itemNo.size() == 0) { MessageWin.showNoticeWin({ message : "请选择一条记录!" }); return; } var result = {}; result.itemId = itemNo.val(); result.itemCode = itemNo.attr("itemCode"); result.itemName = itemNo.attr("itemName"); window.returnValue = result; window.close(); }
我的调用,错误:
function selectItems(){var url = "${path}/item/selectItems.action";var ww = "";var h = 500;var w = 750;var returnValue = showDailogWindow(url,ww, h, w);if(returnValue && returnValue.indexOf(',')!=-1){var vs = returnValue.split(',');$("#projectNo").val(vs[1]);$("#declarationName").val(vs[2]);$("#declarationName").focus();} }
我的调用,正确:
function selectItems(){var url = "${path}/item/selectItems.action";var ww = "";var h = 500;var w = 750;var returnValue = showDailogWindow(url,ww, h, w);if(returnValue){$("#projectNo").val(returnValue.itemCode);$("#declarationName").val(returnValue.itemName);$("#declarationName").focus();} }
4.Action页面控制
Action - 关闭: HttpServletResponse response = ServletActionContext.getResponse(); try { response.getWriter().write("<script type=\"text/javascript\">window.close();</script>"); } catch (IOException e) { e.printStackTrace(); } struts.xml: <result name="zclist" type="redirect">${path}/agency/applyquery!apply.action</result>