PHP &

后端 未结 10 1809
误落风尘
误落风尘 2021-01-20 13:40

Is this correct? If not what is the correct syntax

I am new to php hence trying to learn.

    

        
10条回答
  •  北荒
    北荒 (楼主)
    2021-01-20 13:54

    It will not work because php is a server-side pre-processor that cannot know anything about the user's browser other than what is provided in the browser's original request, which includes nothing about its current scripting capability.

    Basically, if you want to have rich content beyond the simplistic noscript tags -- they can only add non-scripted content, not hide scripted content -- you have to:

    1. Send all content -- both plain and javascript versions -- to the browser.
    2. Place all non-scripted versions of the html in div or span tags with class="nocript".
    3. Place all scripted versions of the html in div or span tags with class="script".
    4. Set css to start with div.noscript{display:block}, span.noscript{display:inline}, .script{display:none}.
    5. Have your javascript hide each element with class="noscript" with element.style.display='none', show each div with class="script" with element.style.display='block' and show each span with class="script" with element.style.display='inline'.

    You also have to consider that a browser is an especially hostile environment to be programming into, as the user, or any plugins, can do anything, like disable javascript, at any time. Therefore, you have to double-check everything that the browser sends, whether by form or AJAX, in your PHP code to make sure it is complete and not corrupt.

提交回复
热议问题