这是我的博客,我在博客中添加了以下代码。下面的代码可以像下面的示例一样在片段中正常工作,但是在我的博客中却无法正常工作,我应该在博客平台中使用它,如果我使用任何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:
(function() {
// your code here
});
(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';
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句