无法从输入字段中获取值onclick

时间:2014-07-07 16:03:08

标签: javascript jquery html flexslider

我有一个输入字段,可以在flex滑块的其中一张幻灯片中输入电子邮件。我无法从相邻按钮的onclick上的输入字段中获取值。我尝试过.val(),. html()和.text()。是的,我知道.val()必须用于输入文本,但为什么它不起作用?即使在控制台中,Everything也会返回一个空字符串。

这是输入字段

<input id="newsletterEmail" type="email" style="margin-right:10px;">
<input id="newsletterSubscription" type="button" value="Subscribe"  onclick="subscribeNewsletter();">

我尝试获取值

$('#newsletterEmail').val()

我根据条件动态追加滑块。当我最初输入HTML时,我得到的值是相关的,所以我想问题是添加内容。我已经使用delegate / on来访问动态按钮,但是有任何这样的特殊情况来从输入字段获取值。我将内容添加为字符串,如下所示:

    var sliderContent = '<div class="flexslider" id="banner_slider"><ul class="slides"><li id="simple_banner"><div class="loginHolder containerBanner clearfix"><div class="leftContent"><img id="homePageHeroImage" class="img-responsive logoBanner1 bannerSliderImg" src="/assets/Logo_banner1.png" alt="Logo_banner1"><p id="logoContent">Why drive for it?</p><p class="centralize" id="stretchContent">The premium products you need are just a few clicks away!</p><div class="loginButtons"><input id="loginBut" type="button" value="Login"onClick="window.open("http://app.grasspit.com","_target");" style="margin-right:10px;"><input id="signBut" type="button" value="Sign Up"onClick="window.open("http://app.grasspit.com/?page=signup","target");"></div><p class="mobileImage"><img class="img-responsive" src="/assets/Mobile.png" alt="Mac-and-iPhone"></p></div><div class="rightContent"><img class="img-responsive" src="/assets/Mac-and-iPhone.png" alt="Mac-and-iPhone"></div></div></li><li id="newsletter_banner"><div class="loginHolder containerBanner clearfix newsCont"><div class="leftContent"><img class="img-responsive logoBanner2 bannerSliderImg" src="/assets/newsLetter_logo.png" alt="News Letter Logo"><p id="logoContent">Subscribe to Grassp Newsletter</p><p class="centralize" id="stretchContent">to get updates for new products, new locations and special promotions.</p><div class="loginButtons"><input id="newsletterEmail" type="email" style="margin-right:10px;"><input id="newsletterSubscription" type="button" value="Subscribe"></div></div></div></li></ul></div>';

非常感谢任何帮助!

0 个答案:

没有答案