javascript - front-end judgment problem
習慣沉默
習慣沉默 2017-06-12 09:30:24
0
8
787

Excuse me, Master, a page element displays the content of different pages according to different roles. How can we judge it without using the background language PHP? For example, if there is a delete button, the teacher has it but the students don’t. How to implement it without using PHP or other backend? Template engine?

習慣沉默
習慣沉默

reply all(8)
三叔

Generally speaking, get or set this [status information] from the ajax interface/HTML template/localStorage, and then do the corresponding processing in JS.

巴扎黑

According to whether your current user is a student or a teacher, just use js to judge and display accordingly

曾经蜡笔没有小新

If you don’t rely on PHP templates, I personally recommend using the front-end angularjs. Although vue.js also has template judgment, the angularjs style will be more biased towards TP YII and other PHP templates. Of course, you can limit the html display through JS, but the more tags are restricted, the more cumbersome the js becomes

世界只因有你

Method 1: Templates are of course possible
Method 2: When returning to the page, it is also retrieved. Just add an ajax request code to the html header. A small amount of code has little impact on performance. The identity of the teacher or student, Then use js to make judgments and operate the dom. One thing to note here is that if the requirement involves a large number of dom operations, do not use this solution. Optimizing the dom yourself is a troublesome thing.
Method 3: Use a framework such as react to implement it, extract the html elements that need to be changed, and abstract them into components, which is also very efficient. For students who have front-end knowledge, it is recommended to understand the Yiha framework.

左手右手慢动作

First understand how you judge the two roles of teacher and student, and secondly, you can handle the buttons differently based on this judgment

某草草

First, the template engine can meet your needs, but you need to know the syntax corresponding to the template

Second, if you use js to control, you must first understand how you get the identity. Is there a value in the page itself, or do you need to use ajax to get it. After getting the value, write an if to perform the corresponding operation on the element

过去多啦不再A梦

Determine the user type when the page is loaded and load different modules as needed

世界只因有你

iframe loads different iframes to display single-page applications according to different conditions. . . . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!