紧急寻求使用javascrip访问struts2标签tabbedPanel的selectedTab属性的问题 document.getElementById() 不能获得吗,没有用过 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var obj = document.getElementById("tab1") alert(obj.getAttribute("selectedTab")) 标准就是这样,所以正常情况下肯定好使,你可以自己写一个简单的html测试一下 用getAttribute("selectedTab"))是可行的。 我刚做了一个例子。使用getAttribute("selectedTab")的话,用alert输出的结果为null.<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><%@ taglib prefix="s" uri="/struts-tags"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title></title><s:head theme="ajax" /><script type="text/javascript" language="javascript"> function tabChange() { var obj = document.getElementById("tab1"); var str = obj.getAttribute("selectedTab"); alert(str); }</script></head><body> <input type="button" value="left" onclick="tabChange();" id="left"> <input type="button" value="middle" id="middle"> <s:tabbedPanel id="tab1" cssStyle="width:1031px;height:738px;" name="tab1" doLayout="true" closeButton="tab" selectedTab="left"> <s:div id="left" label="受信箱" theme="ajax" cssStyle="background-color:#dddddd"> </s:div> <s:div id="middle" label="検索結果" theme="ajax"> </s:div> <s:div id="right" label="新規作成" theme="ajax"> </s:div> <s:div id="lastright" label="TEST" theme="ajax"> </s:div> </s:tabbedPanel></body></html>上面是我的测试代码。 用html随便写一个就能跑<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <SCRIPT LANGUAGE="JavaScript"> function test(){ alert(document.getElementById("tab1").getAttribute("selectedTab")) }</SCRIPT> </HEAD> <BODY> <form> <div dojoType="TabContainer" style="width:1031px;height:738px;" id="tab1" selectedTab="left" closeButton="tab" doLayout="true"> </div> <input type="button" value="aaaaaaaa" onclick="test()"> </form> </BODY></HTML> 查看源代码,看看所有的代码,是否tab1这个id有重复的 不能获得到的原因现在已经找到。下面是我用firefox察看到的页面代码。<html><head></head><body><textarea id="dojo.widget.RichText.savedContent" style="overflow: hidden; display: none; position: absolute; top: -100px; left: -100px; height: 3px; width: 3px;"/><script type="text/javascript"></script><script src="/Struts2Test/struts/CommonFunctions.js" type="text/javascript"></script><script language="javascript" type="text/javascript"></script><input id="left" type="button" onclick="tabChange();" value="left"/><input id="middle" type="button" value="middle"/><script type="text/javascript"></script><div id="tab" class="dojoTabContainer dojoLayoutContainer" style="width: 1031px; height: 738px;"><div class="dojoTabLabels-top dojoAlignTop" dojoattachevent="onKey" wairole="tablist" role="wairole:tablist" style="left: 0px; top: 0px; bottom: auto; right: auto; width: 1031px;"> <div class="dojoTab" dojoattachevent="onClick" dojoinsertionindex="0"><div dojoattachpoint="innerDiv"><span wairole="tab" tabindex="0" dojoattachpoint="titleNode" role="wairole:tab" style="-moz-user-select: none;">Receive</span><span class="close closeImage" dojoattachevent="onMouseOver:onCloseButtonMouseOver; onMouseOut:onCloseButtonMouseOut; onClick:onCloseButtonClick" style="" dojoattachpoint="closeButtonNode"/></div></div><div class="dojoTab" dojoattachevent="onClick" dojoinsertionindex="1"></div><div class="dojoTab current" dojoattachevent="onClick" dojoinsertionindex="2"></div><div class="dojoTab" dojoattachevent="onClick" dojoinsertionindex="3"></div></div><div class="dojoTabPaneWrapper dojoAlignClient" wairole="tabpanel" dojoattachevent="onKey" dojoattachpoint="containerNode" role="wairole:tabpanel" style="left: 0px; top: 25px; bottom: auto; right: auto; width: 1029px; height: 711px;"><div id="left" class="dojoTabPane" showerror="true" label="Receive" style="background-color: rgb(221, 221, 221); width: 1029px; height: 711px;" dojotype="struts:BindDiv"/><div id="middle" class="dojoTabPane" showerror="true" label="Selected" dojotype="struts:BindDiv" style="display: none;"/><div id="right" class="dojoTabPane" showerror="true" label="Create" dojotype="struts:BindDiv" style="display: none;"/><div id="lastright" class="dojoTabPane" showerror="true" label="TEST" dojotype="struts:BindDiv" style="display: none;"/></div></div></body></html>注意红色部分,其实使用直接察看页面代码的方式查看到的<div dojoType="TabContainer" style="width:1031px;height:738px;" id="tab1" selectedTab="left" closeButton="tab" doLayout="true"> 根本就不存在。 我需要修改<div class="dojoTab" dojoattachevent="onClick" dojoinsertionindex="0">中的class属性。但是我现在又是能够访问dojoattachevent和dojoinsertionindex访问不了class。我已经不敢相信我所看到的class是不是真的存在了。所以打算放弃使用struts2标签了,想办法用别的方法实现了。 帖子一段时间内我还不会结的如果大家有时间和兴趣的话,希望能够一起研究struts2的标签。 servlet:Cannot call sendError() after the response has been committed 用了struts,tomcat启动就出错 关于spark皮肤问题 eclipse3.2支持什么版本的jboss 请教:关于java写收邮件程序的字符集问题 Java程序在IBM JDK下运行出错,版主救命!!!!!!! hibernate中使用sequence问题 急 struts的问题,有点晕!(江湖救急) ejb起步 有编写JAVA-BEAN的好工具 spring和iBatis 整合时,配置事务出现的问题 ssh中哪个框架最重要,哪个最容易学
alert(obj.getAttribute("selectedTab"))
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<s:head theme="ajax" /><script type="text/javascript" language="javascript">
function tabChange()
{
var obj = document.getElementById("tab1");
var str = obj.getAttribute("selectedTab");
alert(str);
}
</script>
</head>
<body>
<input type="button" value="left" onclick="tabChange();" id="left">
<input type="button" value="middle" id="middle">
<s:tabbedPanel id="tab1"
cssStyle="width:1031px;height:738px;" name="tab1" doLayout="true"
closeButton="tab" selectedTab="left">
<s:div id="left" label="受信箱" theme="ajax"
cssStyle="background-color:#dddddd">
</s:div>
<s:div id="middle" label="検索結果" theme="ajax"> </s:div>
<s:div id="right" label="新規作成" theme="ajax"> </s:div>
<s:div id="lastright" label="TEST" theme="ajax">
</s:div>
</s:tabbedPanel>
</body>
</html>
上面是我的测试代码。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
function test(){
alert(document.getElementById("tab1").getAttribute("selectedTab"))
}
</SCRIPT>
</HEAD> <BODY>
<form>
<div dojoType="TabContainer"
style="width:1031px;height:738px;" id="tab1" selectedTab="left" closeButton="tab" doLayout="true">
</div>
<input type="button" value="aaaaaaaa" onclick="test()">
</form>
</BODY>
</HTML>
下面是我用firefox察看到的页面代码。
<html>
<head>
</head>
<body>
<textarea id="dojo.widget.RichText.savedContent" style="overflow: hidden; display: none; position: absolute; top: -100px; left: -100px; height: 3px; width: 3px;"/>
<script type="text/javascript">
</script>
<script src="/Struts2Test/struts/CommonFunctions.js" type="text/javascript">
</script>
<script language="javascript" type="text/javascript">
</script>
<input id="left" type="button" onclick="tabChange();" value="left"/>
<input id="middle" type="button" value="middle"/>
<script type="text/javascript">
</script>
<div id="tab" class="dojoTabContainer dojoLayoutContainer" style="width: 1031px; height: 738px;">
<div class="dojoTabLabels-top dojoAlignTop" dojoattachevent="onKey" wairole="tablist" role="wairole:tablist" style="left: 0px; top: 0px; bottom: auto; right: auto; width: 1031px;">
<div class="dojoTab" dojoattachevent="onClick" dojoinsertionindex="0">
<div dojoattachpoint="innerDiv">
<span wairole="tab" tabindex="0" dojoattachpoint="titleNode" role="wairole:tab" style="-moz-user-select: none;">Receive</span>
<span class="close closeImage" dojoattachevent="onMouseOver:onCloseButtonMouseOver; onMouseOut:onCloseButtonMouseOut; onClick:onCloseButtonClick" style="" dojoattachpoint="closeButtonNode"/>
</div>
</div>
<div class="dojoTab" dojoattachevent="onClick" dojoinsertionindex="1">
</div>
<div class="dojoTab current" dojoattachevent="onClick" dojoinsertionindex="2">
</div>
<div class="dojoTab" dojoattachevent="onClick" dojoinsertionindex="3">
</div>
</div>
<div class="dojoTabPaneWrapper dojoAlignClient" wairole="tabpanel" dojoattachevent="onKey" dojoattachpoint="containerNode" role="wairole:tabpanel" style="left: 0px; top: 25px; bottom: auto; right: auto; width: 1029px; height: 711px;">
<div id="left" class="dojoTabPane" showerror="true" label="Receive" style="background-color: rgb(221, 221, 221); width: 1029px; height: 711px;" dojotype="struts:BindDiv"/>
<div id="middle" class="dojoTabPane" showerror="true" label="Selected" dojotype="struts:BindDiv" style="display: none;"/>
<div id="right" class="dojoTabPane" showerror="true" label="Create" dojotype="struts:BindDiv" style="display: none;"/>
<div id="lastright" class="dojoTabPane" showerror="true" label="TEST" dojotype="struts:BindDiv" style="display: none;"/>
</div>
</div>
</body>
</html>
注意红色部分,其实使用直接察看页面代码的方式查看到的
<div dojoType="TabContainer"
style="width:1031px;height:738px;" id="tab1" selectedTab="left" closeButton="tab" doLayout="true">
根本就不存在。
但是我现在又是能够访问dojoattachevent和dojoinsertionindex访问不了class。
我已经不敢相信我所看到的class是不是真的存在了。
所以打算放弃使用struts2标签了,想办法用别的方法实现了。