This article shares the specific code for JavaScript to switch styles between computer and mobile versions for your reference. The specific content is as follows
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> ul{ list-style: none; } </style> </head> <body> <ul> <li>front page</li> <li>Company Profile</li> <li>Product Introduction</li> <li>Success stories</li> <li>Partners</li> </ul> <div> <button onclick="addStyle()">Add style effects</button> <button onclick="showStyle('pc')">Computer version</button> <button onclick="showStyle('mobile')">Mobile version</button> </div> <script> function addStyle() { //Get element according to element tagname var lis = ('li'); for(var i = 0;i<;i++) { lis[i]. = '150px'; lis[i].= '30px'; lis[i]. = '5px 10px'; lis[i]. = '1px'; lis[i]. = 'rgb(51,51,51)'; lis[i]. = 'center'; lis[i]. = '30px'; lis[i].='#fff'; } } function showStyle(type) { var lis = ('li'); for(var i = 0;i<;i++){ if(type == 'pc'){ //PC version lis[i]. = 'left';//Float left //Remove the specified attribute lis[i].('clear'); lis[i].='150px'; }else{ //Mobile version lis[i]. = 'both';//Clear the float lis[i].='100%'; } } } </script> </body> </html>
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.