好的,在几个网站的帮助下,我能够将这些代码放在一起,以停用网站的响应式代码,并激活非响应式代码。但是,当再次单击该链接时,它不会反向执行此功能。
我试着用".toggle",但不起作用。我应该使用哪个事件来获得此效果?任何帮助都是最好的!
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#togglerwd").click(function() {
$('meta[name="viewport"]').prop('content', 'width=1440');
});
});
</script>
<a href="#" id="togglerwd">Toggle Responsive Layout</a>发布于 2015-10-13 15:28:30
不是有一个事件允许代码在超链接被单击时处于活动和非活动状态吗?
单击本身就是正在发生的事件--但该事件并不知道页面当前所处的“状态”。
“标志”是一种常见的编程基础,并不是特定于jQuery或JavaScript的。基本上,它只是一个变量,它的值在true和false之间交替,您可以根据它来决定要做什么。
它看起来像这样:
$(document).ready(function (e) {
// set the initial flag value, we assume your page “starts” in responsive mode
var isResponsive = true;
$("#togglerwd").click(function() {
// check flag, to see what state the page is in
if(isResponsive) {
// set viewport meta to “non-responsive”
$('meta[name="viewport"]').prop('content', 'width=1440');
// remember current state in flag for check on next click
isResponsive = false;
}
else {
// set viewport meta to “responsive”
$('meta[name="viewport"]').prop('content', 'width=device-width');
// remember current state in flag for check on next click
isResponsive = true;
}
});
});发布于 2015-10-14 04:01:28
非常感谢你的帮助,CBroe,但我最终创建了我想要的解决方案。代码如下:
<script>
$(document).ready(function () {
$("#togglerwd").click(function() {
$('meta[name="viewport"]').prop('content', 'width=1440');
});
$("#togglerrl").click(function() {
$('meta[name="viewport"]').prop('content', 'width=device-width');
});
});
</script>
<a href="#" id="togglerwd">Full Site | </a>
<a href="#" id="togglerrl">Responsive Layout</a>https://stackoverflow.com/questions/33090865
复制相似问题