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?
三叔2017-06-12 09:32:24
Generally speaking, get or set this [status information] from the ajax interface/HTML template/localStorage, and then do the corresponding processing in JS.
巴扎黑2017-06-12 09:32:24
According to whether your current user is a student or a teacher, just use js to judge and display accordingly
曾经蜡笔没有小新2017-06-12 09:32:24
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
世界只因有你2017-06-12 09:32:24
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.
ringa_lee2017-06-12 09:32:24
First understand how you judge the two roles of teacher and student, and secondly, you can handle the buttons differently based on this judgment
某草草2017-06-12 09:32:24
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梦2017-06-12 09:32:24
Determine the user type when the page is loaded and load different modules as needed
世界只因有你2017-06-12 09:32:24
iframe loads different iframes to display single-page applications according to different conditions. . . . .