좋아, 이제이 문제를 해결하기 위해 노력했으며 지금은 약간의 도움을 요청하고 있습니다.표시/숨기기 기능의 링크 텍스트 변경
나는 id가 show1과 show2 인 두 개의 단락을 가지고있다.
나는 위에있는 링크를 클릭 할 때마다 확장해야하는 각각의 짧은 텍스트가 있습니다.
내 함수는 확장 및 축소 기능을 수행하지만 링크의 값을 얻지 못한다고 느낀다. 링크 텍스트가 "link is null"이기 때문에 링크 텍스트가 정확하지 않은 것처럼 느껴진다.
var 상태와 innerHTML까지 모두 작동합니다. 두 줄을 주석 처리하면 잘 보이지 않으므로 내 링크 텍스트가 show에서 hide로 바뀝니다. 그래서 어떤 종류의 영혼이 나를 도울 수 있다면 대단히 감사하겠습니다. 함수의 showHide에서
/* Function created by "Simon Willson" to be able to
call several functions with a single event */
//Create the function
function addLoadEvent(func) {
//Create a variable for window.onload event
var oldonload = window.onload;
//If window.onload is NOT a function, then assign 'func' to window.onload
if (typeof window.onload != 'function') {
window.onload = func;
//If window.onload already is a function then make a new function
} else {
window.onload = function() {
//To do what the old onload function did
if (oldonload) {
oldonload();
}
//then do whatever the new function does
func();
}
}
}
function newLink() {
//Make a few safety check to see if the browser can handle the elements
if (!document.getElementById) {
if (!document.createElememt) {
if (!document.createTextNode) {
return false;
}
}
}
//Create the link
newLinkElement = document.createElement('a');
//Give the link a Id
newLinkElement.id = 'show1_link';
//Set the href
newLinkElement.href = "javascript:showHide(this.id,'show1')";
//Create a variable for the link text
var linkText = document.createTextNode('Visa mera information');
//Append the text to the link
newLinkElement.appendChild(linkText);
//Create a variable for the paragraph
var elem = document.getElementById('show1')
//Insert the text before the paragraph with the Id show1
elem.parentNode.insertBefore(newLinkElement,show1);
}
addLoadEvent(newLink);
function showHide(link_id,elemId) {
var link = document.getElementById(link_id);
var text = document.getElementById(elemId);
text.style.display = (text.style.display == 'block') ? 'none' : 'block';
var status = (text.style.display == 'block') ? 'none' : 'block';
text.style.display = status;
link.innerHTML = (status == 'block') ? 'Dölj information' : 'Visa mera information';
}
[데모를 보여 드릴 수 있습니까?] (http://jsfiddle.net/) 우리가 함께 할 수 있습니까? –
addLoadEvent 함수를 포함하도록 자바 스크립트를 편집하면 페이지가 오프라인 상태가됩니다 ... 두 개의 단락이있는 기본 html 문서 p class = "show"id = "show1"두 번째 ID는 "show2"입니다. – Angel