无法设置未定义的属性“class”

时间:2017-07-13 10:40:34

标签: css xpages client-side

我确定我做了一些愚蠢的事情,或者遗漏了一些愚蠢的事情,但我从客户端点击了一个按钮后得到了以下2条错误消息:

  

无法设置未定义的属性“class”

     

无法设置属性'scrollTop'为null

我要做的就是为inputTextArea设置样式,然后滚动到我可以滚动的内容div的顶部。

    document.getElementById(x$("#{id:obj1Error}").Attributes["class"] = "has-error");
    var myDiv = document.getElementById(x$("#{id:contentWhiteBackground}"));
    myDiv.scrollTop = 0;

任何指针都表示赞赏。干杯

更新:

按钮上的客户端代码:

// Make sure user has entered content into the first objective at minimum
var objcolparent = document.getElementById("ObjColOuter").children[0];
var objValue = objcolparent.getElementsByTagName("TEXTAREA")[0].value;

if(objValue ==""){
var o = {};
o.title = "Validation Failed";
o.body = "You must enter at least one objective before submitting";
o.alertIcon = "fa-thumbs-down fa-lg";
o.alertType = "danger";

var myDiv = document.getElementById("#{id:contentWhiteBackground}");
//document.getElementById("#{id:obj1Error}").className = "has-error";
myDiv.scrollTop = 0;
bootAlert.show('alertServer',JSON.stringify(o));
return false;
}

if(confirm("Are you sure you want to submit your objectives?")){
return true;
}else{
return false;
}

xpage上的代码,其中包含obj1Error div:

<xp:repeat id="repeat1" rows="100"
                            value="#{viewScope.fields}" var="fieldName">

                            <xp:text escape="true"
                                id="computedField4" styleClass="h5">


                                <xp:this.value><![CDATA[#{javascript:"Objective "+@RightBack(fieldName, 16)}]]></xp:this.value>
                            </xp:text>
                            <br />
                            <xp:div id="obj1Error">

                                <xp:text escape="true"
                                    id="computedField1" styleClass="h6">



                                    <xp:this.value><![CDATA[#{javascript:"Details"}]]></xp:this.value>
                                </xp:text>
                                <xp:inputTextarea
                                    id="inputTextarea1" style="height:100px;resize:none;"
                                    showReadonlyAsDisabled="true">
                                    <xp:this.value><![CDATA[#{document1[fieldName]}]]></xp:this.value>
                                    <xp:this.disabled><![CDATA[#{javascript:try{

var strStatus:string = document1.getItemValueString("status"); 
var booDisabled:boolean = true;

if(strStatus == "New" || strStatus == "Draft" || strStatus == "Returned") {
booDisabled = false;
}

return booDisabled;

}catch(e){
writeToLog("Error - ccObjectives disable objective details: " + e);
}}]]></xp:this.disabled>

                                </xp:inputTextarea>
                            </xp:div>
                            <br />
                        </xp:repeat>

2 个答案:

答案 0 :(得分:2)

你只需要写

var myDiv = document.getElementById("#{id:contentWhiteBackground}");

获取DOM元素。

要设置元素的类,您必须编写:

document.getElementById("#{id:obj1Error}").className = "has-error";

答案 1 :(得分:1)

我建议使用xpages中的dojo toolkit而不是本机javascript:

dojo.addClass('#{id:obj1Error}','has-error');
var myDiv = dojo.byId('#{id:contentWhiteBackground}');
myDiv.scrollTop = 0;