0

我正在尝试使用此内容切换器

当我将联系表格放在隐藏的 div 中时,它不起作用。如果我将它放在内容切换器之外,它就可以工作。

我知道由于切换器 jquery 代码,没有要获取的源 html,这就是它不起作用的原因。但我真的需要让它在那个切换器中工作。有什么办法让它工作吗?

的HTML:

<div id="content3-content" class="message switcher-content">                
<p class="medium">Contact Form</p>
<form class="contact" id="contact">
<div class="form">
<input type="text" name="name" placeholder="Name" id="contactname" />
<input type="text" name="email" placeholder="Email" id="contactemail" />
<textarea name="message" placeholder="Message" id="contactmessage"></textarea>
<button>Send</button>
</div>
</form>
</div>

内容切换器 JS:

 /* jQuery Content Panel Switcher JS - v1.1 */
    var jcps = {};
    jcps.fader = function(speed, target, panel) {
    jcps.show(target, panel);
    if (panel == null) {panel = ''};
    $('.switcher' + panel).click(function() {
        var _contentId = '#' + $(this).attr('id') + '-content';
        var _content = $(_contentId).html();
        if (speed == 0) {
            $(target).html(_content);
        }
        else {  
            $(target).fadeToggle(speed, function()    {$(this).html(_content);}).fadeToggle(speed);
        }
    });
};
jcps.slider = function(speed, target, panel) { 
    jcps.show(target, panel);
    if (panel == null) {panel = ''};
    $('.switcher' + panel).click(function() {
        var _contentId = '#' + $(this).attr('id') + '-content';
        var _content = $(_contentId).html();
        if (speed == 0) {
            $(target).html(_content);
        }
        else {  
            $(target).slideToggle(speed, function(){$(this).html(_content);}).slideToggle(speed);
        }
    });
};
jcps.show = function (target, panel) {
$('.show').each(function() {
    if (panel == null) {
        $(target).append($(this).html() + '<br/>');
    }
    else {
        var trimPanel = panel.replace('.', '');
        if ($(this).hasClass(trimPanel) == true){$(target).append($(this).html() + '<br/>');}
    }
});
}
4

1 回答 1

0

这是一个FIDDLE,这是你想要的吗?

<a href="#" id="content1" class="switcher">Content 1</a> 
<a href="#" id="content2" class="switcher">Content 2</a>
<a href="#" id="content3" class="switcher">Content 3</a>

<div id="switcher-panel"></div>

<div id="content1-content" class="switcher-content show">Content 1</div>

<div id="content2-content" class="switcher-content">Content 2</div>

<div id="content3-content" class="switcher-content">                
  <p class="medium">Contact Form</p>
  <form class="contact" id="contact">
    <input type="text" name="name" placeholder="Name" id="contactname" />
    <input type="text" name="email" placeholder="Email" id="contactemail" />
    <textarea name="message" placeholder="Message" id="contactmessage"></textarea>
    <button>Send</button>
  </form>
</div>


#switcher-panel {
  padding-top: 25px;
}
#content1-content,
#content2-content,
#content3-content {
  display: none;
}
form {
  width: 350px;
}
input[type="text"] {
  float: left;
  width: 220px;
  margin-bottom: 10px;
}
textarea {
  float: left;
  width: 218px;
  height: 100px;
  margin-bottom: 10px;
}
button {
  float: left;
  clear: left;
}
于 2013-09-21T05:57:12.900 回答