日期:2014-05-16  浏览次数:20545 次

跪求各位高手帮我解决此问题,报错:ID/NAME 所引用的元素位于全局范围。请使用 W3C 的标准形式 document.getElementB
下面贴代码
HTML code

<td noWrap width="20%">
    <div>
    <textarea  id="msgContentArea" rows="15" cols="40"
    onPropertyChange="javascript:setMsg();"></textarea>
<span><font color="red">*</font></span>
    </div>
</td>

<th><app:i18n key="page.9.wordcount"/>:</th>
    <td colspan="2">
    <font color="red"><app:SmsContextTag form="PolicyFormBean" formfield="msgPreview" /> </font>
</td>



js代碼將textare中的值獲取到,在後臺判斷,在傳回前臺
JScript code

        function setMsg(){
            //获取短信内容和签名状态
            var previewMsg = "";
            var msgContentArea=$("#msgContentArea");
            previewMsg += msgContentArea.val();
            var nameFlagObjs = document.getElementsByName("nameFlag");
            var nameFlag = false;
            var userName = "";
            if(nameFlagObjs[1].checked){
                nameFlag = true;
                userName = document.getElementsByName("currentName")[0].value;
            }
            if(nameFlag)
                previewMsg += "[" + userName + "]";
            if(msgContentArea.val()=="")
                previewMsg = "";
            [color=#FF0000]PolicyFormBean.msgPreview.value[/color] = previewMsg;
        }





後臺程序
Java code

        System.out.println(longsmsenglishlength);
        System.out.println(longsmschineselength);
        StringBuffer sb = new StringBuffer();

        sb.append("<script language=\"javascript\">\n");
        sb.append("var submitflag = false;\n");
        sb.append("function checkSmsContext(send_content){\n");
        
        
        //sb.append("alert(send_content);");
        
        sb.append("var strlength=0;\n");
        sb.append("var iList=0;\n");
        sb.append("var maxlengths=134;\n");
        sb.append("var firstmax=140;\n");
        sb.append("send_content = send_content.replaceAll('\\r','');\n");
        
        //sb.append("alert(send_content);");
        
        sb.append("if( isChinese( send_content ) ){\n");
        sb.append("firstmax=140;\n");
        sb.append("strlength = send_content.length * 2;\n");
        sb.append("}else{\n");
        sb.append("firstmax=140;\n");
        sb.append("strlength = send_content.length;\n");
        sb.append("} \n");
        sb.append("if( strlength<=firstmax ){\n");
        sb.append("iList=1;");
        sb.append("}else{\n");
        sb.append("if( strlength%maxlengths==0 ){\n");
        sb.append("iList = parseInt( strlength/maxlengths );\n");
        sb.append("}else{\n");
        sb.append("iList = parseInt( strlength/maxlengths ) + 1;\n");
        sb.append("}\n");
        sb.append("}\n");
        sb.append("if(strlength >800){\n");
        sb.append("submitflag=false;}\n");
        sb.append("else{\n");
        sb.append("submitflag=true;\n");
        sb.append("}\n");
        
        
        sb.append("document.getElementsByName(\"