这段代码在snippet中工作,但在blogger中不工作
This code is working in snippet but not in blogger
这是我的博客,我在博客中添加了如下代码。下面的代码在代码段中正常工作,就像下面的例子一样,但它在我的博客中不正常工作,如果我使用任何jquery库使其工作,我会在博客平台中使用它。请参阅下面的代码段,它在代码段中运行良好。我的目标是,如果另一个小部件显示,但在我的博客中同时显示了两个小部件,则隐藏一个小程序。示例小提琴工作良好
<script type="text/javascript">
var control1VisibleCheck = function () {
var now = new Date();
//TODO: modify this logic to your needs: have a look on the Date() object's members and methods to implement what you need
if (now.getSeconds() % 20 == 0) //I'd like to show control1 on even minutes
return true;
return false;
}
if (control1VisibleCheck())
document.getElementById('multi-search-groups').style.display = 'none';
else
document.getElementById('multi-search').style.display = 'none';
</script>
<div id="multi-search">
<select id="cmbColumn" name="cmbColumn">
<option value="" />Columns
<option value="apple+" />apple
<option value="grapes+" />grapes
</select>
<select id="cmbSidebar" name="cmbSidebar">
<option value="" />Sidebars
<option value="mango+" />mango
<option value="berry+" />berry
</select>
</div>
<div id="multi-search-groups">
<em>Multiple Select with Groups</em><br />
<select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6">
<option value="" />
<optgroup label="NFC EAST">
<option />Dallas Cowboys
<option />New York Giants
<option />Philadelphia Eagles
<option />Washington Redskins
</optgroup>
</select>
</div>
<!--div id="control1" style="width: 200px; height: 100px; background-color: red;">
</div>
<div id="control2" style="width: 200px; height: 100px; background-color: green;">
</div-->
以下代码运行良好
var control1VisibleCheck = function () {
var now = new Date();
//TODO: modify this logic to your needs: have a look on the Date() object's members and methods to implement what you need
if (now.getSeconds() % 2 == 0) //I'd like to show control1 on even minutes
return true;
return false;
}
if (control1VisibleCheck())
document.getElementById('multi-search-groups').style.display = 'none';
else
document.getElementById('multi-search').style.display = 'none';
<div id="multi-search">
<select id="cmbColumn" name="cmbColumn">
<option value="" />Columns
<option value="apple+" />apple
<option value="grapes+" />grapes
</select>
<select id="cmbSidebar" name="cmbSidebar">
<option value="" />Sidebars
<option value="mango+" />mango
<option value="berry+" />berry
</select>
</div>
<div id="multi-search-groups">
<em>Multiple Select with Groups</em><br>
<select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6">
<option value=""></option>
<optgroup label="NFC EAST">
<option>Dallas Cowboys</option>
<option>New York Giants</option>
<option>Philadelphia Eagles</option>
<option>Washington Redskins</option>
</optgroup>
</select>
</div>
<!--div id="control1" style="width: 200px; height: 100px; background-color: red;">
</div>
<div id="control2" style="width: 200px; height: 100px; background-color: green;">
</div-->
似乎你的小提琴也不能正常工作,正如评论中所建议的那样,在页面(文档)准备好后执行你的JavaScript:
JavaScript文档就绪功能
(function() {
// your code here
});
完整的JavaScript:
(function() {
var control1VisibleCheck = function () {
var now = new Date();
//TODO: modify this logic to your needs: have a look on the Date() object's members and methods to implement what you need
if (now.getMinutes() % 2 == 0) //I'd like to show control1 on even minutes
return true;
return false;
}
if (control1VisibleCheck())
document.getElementById('multi-search-groups').style.display = 'none';
else
document.getElementById('multi-search').style.display = 'none';
});
工作JSFiddle
已解决!我在</div>
标签之后添加了我的<script>
,它的工作原理如下,这是我在博客中得到的代码。
我得到了我想要的结果,我的意思是,如果一个小部件被隐藏,另一个小程序被显示出来,我使用了if (now.getSeconds() % 2 == 0)
,下面是我在博客中添加的完整代码。我刚刚改变了,我的意思是我在div
之后添加了script
标签,它起作用了。
<div id="multi-search">
<select id="cmbColumn" name="cmbColumn">
<option value="" />Columns
<option value="apple+" />apple
<option value="grapes+" />grapes
</select>
<select id="cmbSidebar" name="cmbSidebar">
<option value="" />Sidebars
<option value="mango+" />mango
<option value="berry+" />berry
</select>
</div>
<div id="multi-search-groups">
<em>Multiple Select with Groups</em><br />
<select data-placeholder="Your Favorite Football Team" style="width:350px;" class="chosen-select" multiple tabindex="6">
<option value="" />
<optgroup label="NFC EAST">
<option />Dallas Cowboys
<option />New York Giants
<option />Philadelphia Eagles
<option />Washington Redskins
</optgroup>
</select>
</div>
<script type="text/javascript">
var control1VisibleCheck = function () {
var now = new Date();
//TODO: modify this logic to your needs: have a look on the Date() object's members and methods to implement what you need
if (now.getSeconds() % 2 == 0) //I'd like to show control1 on even minutes
return true;
return false;
}
if (control1VisibleCheck())
document.getElementById('multi-search-groups').style.display = 'none';
else
document.getElementById('multi-search').style.display = 'none';
</script>
相关文章:
- JavaScript获胜't运行,但在jsFiddle中工作
- Javascript的某些部分在Chrome中不起作用,但在其他浏览器中可以完美工作
- appendChild在函数外部工作,但在函数内部不工作
- 为什么这个jQuery可以作为一个小提琴工作,但在我的网页上没有
- Var工作,但在使用数组执行相同操作时停止
- jQuery REST会话没有'不工作,但在POSTMan工作
- 我的时间倒计时脚本在谷歌浏览器中工作正常,但在其他浏览器中打开时它显示为南楠
- 引导程序's的javascript在本地工作,但在部署到服务器时不能工作
- javascript代码,用于删除firefox中的空白,但在IE和chrome中无法正常工作
- 无法从IE中的data.responseText获取结果,但在其他浏览器中工作
- 复杂选择器在jQuery 1.8中中断,但在1.7.2中工作
- 意思是.js - 登录后重定向用户 - 在本地工作,但在部署时不起作用
- 火狐中的多个问题,但在 chrome 中工作正常,没有一个问题
- jQuery选择器在脚本中不起作用,但在控制台中工作
- 在键上验证正在工作,但在按键时它不起作用
- blur() 无法以编程方式工作 |但在从用户启动时会这样做
- 在暂存服务器中工作但在生产中失败的无效 URL
- 使用angular-google-maps指令在“grunt服务”期间工作.但在默认的grunt任务期间不会
- 将子项链接到在Chrome中工作但在Internet Explorer中不工作的按钮
- Blob createObjectURL下载在Firefox中不工作(但在调试时工作)