Go to div of another page in HTML

前端 未结 3 1172
遥遥无期
遥遥无期 2021-01-12 23:42

I would like to go to the DIV of a particular page from a different page. Is that possible?

I tried Hello<

相关标签:
3条回答
  • 2021-01-12 23:45

    With HTML 5, you need to simply add an id attribute to your <div> with a value of product. This needs to be a unique id attribute within the page (for all elements):

    <div id="product">
    

    See the working draft.

    In HTML 4.01 you need to use an anchor tag with a name just above your target div, or any other element with an id attribute in the other page:

    <a name="product"></a>
    <div>...
    

    See the HTML 4.01 spec.

    Note: The name attribute has been deprecated in the XHTML 1.0 spec.

    So, this would be a better option, as it would work for HTML 4.01, XHTML 1.0 and HTML 5:

    <div id="product">
    
    0 讨论(0)
  • 2021-01-12 23:46

    file.html will need an element with an id="product" attribute. name is deprecated for <a> tags and shouldn't be used.

    <div id="product"></div> 
    
    0 讨论(0)
  • 2021-01-12 23:52

    Don't use an anchor. That is outdated. Just give the DIV the id product:

    <div id="product">...</div>
    
    0 讨论(0)
提交回复
热议问题