Home > front end >  Javascript to hide button is not successful
Javascript to hide button is not successful

Time:09-26

When demand is this: open the web page by judgment is WeChat within the browser, mobile browser, the browser or computer end, according to the different browsers display button for the next operation, determine whether can normally now, is the document. The getElementById (" test "). Style. The display=' '; Way can't hide button, tried a different approach, or can't hide, don't know what the reason, the code is as follows:
 
<script>
The function IsPC () {
var userAgentInfo=navigator.userAgent;
var Agents=new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
var flag=true;
For (var v=0; V & lt; Agents. Length; V++) {
If (userAgentInfo. IndexOf (Agents [v]) & gt; 0 {
//mobile browser
Flag=false;
Document. The getElementById (" noWeiXin ") style. The display='block';
break;
}
The else {
//PC browser
Alert (' no ');
Document. The getElementById (" test "). Style. The display=' ';//hide
break;
}
}
return flag;
}
//determine whether WeChat login
The function isWeiXin () {
Var ua=window. The navigator. UserAgent. ToLowerCase ();
The console. The log (ua);//mozilla/5.0 (iphone; CPU iphone OS 9 _1 like MAC OS x) applewebkit/601.1.46 (KHTML, like gecko) version 9.0/mobile/13 b143 safari/601.1
If (ua) match (/MicroMessenger/I)=='MicroMessenger') {
return true;
} else {
return false;
}
}
If (isWeiXin ()) {
//alert (" is from WeChat built-in browser ");
//the document. The getElementById (" dl ".) style. The display=' ';
} else {
Alert (" not from WeChat built-in browser ");
IsPC ();
}
</script>


 



CodePudding user response:

Hidden is none is not empty

CodePudding user response:

Not none

CodePudding user response:

Document. The getElementById (" test "). Style. The display='none';

CodePudding user response:

To look at the order of execution, the implementation of the document. The getElementById (" test "). Style. The display, make sure the test is loaded

CodePudding user response:


 
The function IsPC () {
var userAgentInfo=navigator.userAgent;
var Agents=new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
var flag=true;
For (var v=0; V & lt; Agents. Length; V++) {
If (userAgentInfo. IndexOf (Agents [v]) & gt; 0 {
//mobile browser
Flag=false;
Document. The getElementById (" noWeiXin ") style. The display='block';
break;
}
}
If (flag) {
//PC browser
Alert (' no ');
Document. The getElementById (" test "). Style. The display='none';//hide
}
return flag;
}
  • Related