我正试图在切换时更改锚点中的文本.我现在正在这样做,但发现一旦锚标记取代了切换,就不再有效了.有人可以解释为什么会发生这种情况并提供解决方案吗?非常感谢.
$('a#toggleHeader').toggle(function() {
$('#header-wrapper').slideUp();
$(this).replaceWith('< href=\"#\" id="toggleHeader">Show Header</>');
Run Code Online (Sandbox Code Playgroud)
//注意:我移动了锚点,因为我只能将一个锚点作为新用户发布
},function(){
$('#header-wrapper').slideDown();
$(this).replaceWith('<a href=\"#\" id="toggleHeader">Hide Header</a>');
});
Run Code Online (Sandbox Code Playgroud) 我已经开发了这个菜单,带有li元素的sub ul可以使用toggle()单击父li来滑入和滑出.如果显示另一个子ul,则sctipt将其关闭.这与标准链接工作相当不错,但我想用ajax请求替换链接点击,如果页面没有改变,点击嵌套的li链接,使相对子菜单被克隆.
我想在单击链接时阻止子菜单关闭.我试图将点击功能从LI移动到SPAN,但我找不到正确的方法.
javascript:
(function($){
$.fn.extend( {
verticalfade: function(options){
var defaults = {
speed: 'normal'
};
var options = $.extend(defaults, options);
$(this).addClass('verticalFadeMenu');
//close all sub menu
$('ul#verticalfade li ul').each(function(){
$('ul#verticalfade li ul').hide();
});
//toggle sub menu
$('ul#verticalfade li').live('click',function(){
var t = this;
$('ul#verticalfade li').each(function(){
if (this != t)
{
if($(this).children('ul').is(":visible"))
{
$(this).children('ul').toggle(800);
}
}
else
{
$(this).children('ul').toggle(800);
}
});
})
//manage links
$("ul#verticalfade li ul li a").click(function(e){
//prevent default action
e.preventDefault();
});
}
});})(jQuery);
Run Code Online (Sandbox Code Playgroud)
html:
<div id="verticalfade_container">
<ul id="verticalfade">
<li><span>First</span> …Run Code Online (Sandbox Code Playgroud) 单击"+"时,js/jquery代码会在下面列出切换子项的内容?
<ul>
<li id="1" parent="0"><a href="#">1</a></li>
<li id="2" parent="0"><a href="#"> + </a><a href="#">2</a>
<ul parent="2">
<li id="23" parent="2"><a href="#">2.1</a></li>
<li id="50" parent="2"><a href="#"> + </a><a href="#">2.2</a>
<ul parent="50">
<li id="123" parent="50"><a href="#">2.50.1</a></li>
</ul>
</li>
</ul>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建幻灯片转换效果,例如视频http://www.youtube.com/watch?v=SZTiJmclaRc中发布的效果.
当单击按钮时,当前的div#1将向左滑动并隐藏自身,而另一个div#2将从右侧滑动并移动到之前滑出的div的位置.
当按钮再次触发时,div#2将向右滑动,而先前隐藏的div#1将从左侧滑出.
我一直在尝试修改http://jsfiddle.net/qSvDz/上的代码,如下所示,但我似乎无法得到我想要的结果.
谁能和我分享一些如何去做的想法.
function toggleDivs() {
var $home = $("#home");
var $memberHome = $("#member-home");
var $slideOut, $slideIn;
// See which <divs> should be animated in/out.
if ($home.position().left < 0) {
$slideIn = $home;
$slideOut = $memberHome;
}
else {
$slideIn = $memberHome;
$slideOut = $home;
}
$slideOut.animate({
left: "-" + $slideOut.width() + "px"
}, function() {
$slideIn.animate({ left: "0px" });
});
}
$("button").bind("click", function() {
toggleDivs();
});
Run Code Online (Sandbox Code Playgroud)
谢谢火
我动态生成id为chkBox100等的复选框和onClick函数.
我想做的是
我想在没有jquery或任何其他库的标准javascript中执行此操作.
请帮助您的帮助,我们将不胜感激.到目前为止,这是我的代码.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function toggle(chkBox)
{
if (chkBox.checked)
{
chkBox.checked = false;
}
else
{
chkBox.checked = true;
}
// only select one at a time.
}
</script>
</head>
<body>
<form id="myForm" name="myForm">
<input type="checkbox" id="chkBox100" onClick="toggle(this);">
<input type="checkbox" id="chkBox121" onClick="toggle(this);">
<input type="checkbox" id="chkBox1180" onClick="toggle(this);">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我想使用java脚本显示和隐藏按钮.
我的问题是按钮应该在页面加载时隐藏,当我在文本框中更改文本时,应该显示按钮.
谢谢.....
我有一个实例,我想根据点击更改文本和选择框的状态.
$("#foo").click(function(){
$("#mytext").toggle();
$(this).text($(this.text() == 'on' ? 'off' : 'on');
// here i also want to enable and disable a select box, not sure how to do this other then checking if the value of (this).text is on or off.
});
Run Code Online (Sandbox Code Playgroud)
非常感谢!
我试图通过AppleScript检查应用程序是否打开
这是以下代码:
on run {input, parameters}
quit application "KeyboardViewer"
return input
end run
Run Code Online (Sandbox Code Playgroud)
但是我希望它首先检查KeyboardViewer是否打开,如果是,则退出应用程序,如果没有,则启动它.在某种程度上,代码应该切换应用程序.
我不熟悉AppleScript的编码(这里的第一个计时器)所以我很感激一些见解.
谢谢
编辑
我一直在尝试使用它,这似乎有效,是否有更有效的方法?我想看看你的意见
on run {input, parameters}
if application "KeyboardViewer" is running then
quit application "KeyboardViewer"
else
activate application "KeyboardViewer"
end if
return input
end run
Run Code Online (Sandbox Code Playgroud)
使用此脚本时有一个小的(少于1秒)延迟.有没有办法让它更快?
我有一些j-query脚本,切换在悬停在单独的div上时淡化div.div渐渐消失,速度相同.我想要实现的是让鼠标在鼠标悬停时缓慢淡出,但是在鼠标移出后很快就消失了.
我到目前为止的脚本如下所示:
// JS code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#nav1").hover(function(){
$("#splat1").fadeToggle(2000);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
因此,#splat1 div目前在2秒内再次淡入和淡出.我理想的是它会在2秒内消失,但在0.5秒内消失.有什么建议?
我正在尝试在播放和暂停图像之间切换我的按钮,当我开始并使用Swift停止滚动条.我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet var btnPlayPause: UIBarButtonItem!
var isPlaying = false
var timer = NSTimer()
var count = 0
@IBOutlet weak var lblTime: UILabel!
@IBOutlet var myToolbar: UIToolbar!
@IBAction func btnPlay(sender: UIBarButtonItem)
{
//set the button to animate
self.myToolbar.setItems([self.btnPlayPause], animated: true)
if !isPlaying //if the ticker is not ticking
{
//change the button to a pause button
println("worked")//start the ticker
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateTime"), userInfo: nil, repeats: true)
isPlaying = true
}else{ //if …Run Code Online (Sandbox Code Playgroud) toggle ×10
jquery ×6
javascript ×3
applescript ×1
automator ×1
button ×1
checkbox ×1
dynamic ×1
fade ×1
macos ×1
onclick ×1
parent-child ×1
replace ×1
slide ×1
slidetoggle ×1
swift ×1
toolbar ×1