Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript-判断平台类型对应修改相应元素 #2

Open
mkdir1 opened this issue Dec 14, 2015 · 0 comments
Open

javascript-判断平台类型对应修改相应元素 #2

mkdir1 opened this issue Dec 14, 2015 · 0 comments

Comments

@mkdir1
Copy link
Owner

mkdir1 commented Dec 14, 2015

判断平台类型

调用的接口

javacript中有一个var av = navigator.appVersion.toLowerCase() || ''; 这里可以判断对应的平台

修改对应的元素

每个id对应的元素,用下面的方法:

  var id = document.getElementById('id');
  var href = id.href;
  var text = id.innerHTML;

如果还有其它元素,也一样

示例代码

<html>
<body>
<div id="an">
        <a id="desktopClient" target="_blank" hidefocus="true" href="http://githbu.com" title="test">desktop</a>
    </div>
    <script >
    (function (){
     var av = navigator.appVersion.toLowerCase() || '';
     var is = {};
     var dictClientEle = document.getElementById('desktopClient');
     var href = dictClientEle.href;
     var text = dictClientEle.innerHTML;
     is.mac = /mac/i.test(av);
     is.win = /win/i.test(av);
     is.ipad = /ipad/i.test(av);
     is.linux = /linux/i.test(av);
     is.iphone = /iphone/i.test(av);
     is.android = /android/i.test(av);
     if (is.win) {
     href = "http://163.com";
     text = "windows"
     } else if (is.mac) {
     if (is.iphone) {
     href = "http://163.com";
     text = "iphone"
     } else if (is.ipad) {
     href = "http://163.com";
     text = "ipad"
     } else {
         href = "http://163.com";
         text = "Mac"
     }
     } else if (is.linux) {
         href = "http://163.com";
         text = "Linux"
     } else if (is.android) {
         href =  "http://163.com";
         text = "Android"
     }
     dictClientEle.href = href;
     dictClientEle.innerHTML = text;
    })();
    </script>
</body>
</html>

总结

  • 1.获取平台信息
  • 2.修改元素属性
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant