שלח תשובה

זירת השאלות

660
צפיות
4
תשובות

בעיה

,‏ 4 בינואר, 2005

אני רוצה לבנות דבר כזה שיבנה לי תפריט, בצורה של treeview
אז אני עושה טבלה שכאשר לוחצים עליה זה מוסיף לה תת טבלה עם padding וכך זה יצור את הזיח  בינהן, הינה הקוד:


<script language=javascript>
var counter;
counter=1;
function insertElement(id)
{
counter++
document.getElementById("e"+id).innerHTML+="<table border=1><Tr><Td onclick='insertElement("+counter+")' id='e"+counter+"' style='cursor:pointer;padding-left:20px;'>•"+counter+"</td></tr></table>"
}
</script>

<table border=1>
<Tr><Td onclick="insertElement(1)" id="e1" style="padding-left:20px;cursor:pointer" >1</td></tr>
</table>


עכשיו מה שקורה זה שלוחצים על טבלה פנימית זה גם לוחץ על הטבלה שהמכילה  אותה ואז זה מוסיף לי טבלאות בהתאם למיקום של הטבלה שלחצתי עליה, תראו בעצמכם בקובץ המצורף מה קורה בדיוק, אני מעוניין שרק הטבלה שעליה לחצו באמת(שהתככונו ללחץ) יווסף לה טבלה

תודב

תגיות:

4 תשובות

  1. זהר פלד הגיב:

    אממ…
    א) לא צרפת קובץ. כשתצרף את הקובץ אפשר יהיה לראות בדיוק את הבעיה.

    ב) אל תעבוד עם innerHTML בשביל זה, תעבוד עם document.createElement. ועם appendElement. תוכל למצוא עליהם פירוט נרחב ב MSDN.

  2. ניר טייב הגיב:

    |קטנוני| appendChild
    ניתן לקרוא על כל ה-DOM כאן: http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html
    (כמובן שרצוי להפעיל את פונקציית החיפוש של הדפדפן כדי לאתר את המבוקש)
    לגבי appendChild זה מה שכתוב עליו ב-W3C (בקישור הנ"ל):

    appendChild
        Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
        Parameters

        newChild of type Node
            The node to add.
            If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node

        Return Value

        Node
            

        The node added.
        Exceptions

        DOMException
            

        HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors.

        WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.

        NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

    בהצלחה

  3. ShabLuLim הגיב:

    זיהוי תגים בתוך תג
    נגיד יש לי את הקוד הבא:


    <span id=spn1>
    <hr>
    <span>saas</span>
    <table><tr><Td>ds</td></table>
    </span>

    איך אני יכול על ידי פקודה מסויימת לשנות נגיד את התכונה צבע מסגרת לכל האלמנטים בתוך spn1?
    חיפשתי בmsdn ומצאתי משהו childnodes אבל ממש לא הבנתי איך נעשה השימוש בו, אודה אם תוכלו לעשות לי תודה

  4. ניר טייב הגיב:

    כך…

    var childs = document.getElementById("spn1").childNodes
    for(var i=0;i<childs.length;i++){
       childs[i].style.border="1px solid black";
    }

שלח תשובה