jQuery内容切换器(不能让联系表单在里面工作)

时间:2013-09-21 02:15:56

标签: javascript jquery html dom

我正在尝试使用此content switcher

当我将联系表单放在隐藏的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>

Content Switcher 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/>');}
    }
});
}

1 个答案:

答案 0 :(得分: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;
}