我正在尝试为长文本设置截断/显示按钮。但是按钮不起作用,错误消息为"第15行出错未捕获TypeError:无法设置属性' oneclick' null。"
第15行是" button.onclick = function(){"
完整代码
//@Embedded
@Entity
public class Address extends AbstractDomainClass {
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String zipCode;
//new fields...
private int addressType;
@ManyToOne
private Customer customer;
// getters and setters ...
}
@Entity
public class Customer extends AbstractDomainClass {
//other attributes...
@OneToOne(mappedBy="customer", cascade=CascadeType.ALL)
private Address billingAddress;
@OneToOne(mappedBy="customer", cascade=CascadeType.ALL)
private Address shippingAddress;
//getters and setters...
}
答案 0 :(得分:-2)
<script>
window.onload = function(){
var content = document.getElementById("content");
var button = document.getElementById("show-more");
button.onclick = function () {
if(content.className == "open"){
//shrink the box
content.className = "";
button.innerHTML = "SHOW MORE";
} else {
//expand the box
content.className = "open";
button.innerHTML = "SHOW LESS";
}
};
}
</script>