javascript - 将变量传递到 Shadowbox 模态窗口?

标签 javascript jquery email shadowbox

我正在尝试向网站添加电子邮件服务。我弹出了一个带有 Shadowbox 的模式消息窗口(因为我已经在网站上将 Shadowbox 用于其他目的)。

问题是,我似乎无法将变量传递到打开的消息表单中。

我这样调用窗口

$(document).on("click","#mail",function(e){
    e.preventDefault();
    var thisParentClass = $(this).parent().attr("class");
    alert (thisParentClass);
    var thisIDpos = thisParentClass.indexOf("id-")+3;
    var thisID = thisParentClass.substr(thisIDpos, 3);
    alert(thisID);
     Shadowbox.open({
        content:    '<form method="post" class="mailForm" action="#"><input type="hidden" name="memberID" value=thisID><p>Please be advised that the member may not be actively receiving mail.. or they might just not care at all.  They have lives too you know.</p>Your E-mail:<input type="text" name="fromEmail" size="25"> <br>Your Name: <input type="text" name="fromName" size="25"> <br>Your Message: <br><textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br><button type="submit" onclick="return false;" id="mailSubmit" value="Submit">Submit</button> ',
        player:     "html",
        height:     350,
        width:      350,
        options: {modal:true}
});

我的所有警报都返回正确的值,但 [thisID] 没有进入我的消息表单。我只是不断获取“value =“thisID””的 HTML(请注意,无论我是否添加引号,引号都会包围我的变量)。有什么办法可以输入这个变量,或者我必须切换到另一个解决方案吗? (我希望我的窗口看起来都一样,所以如果我不能在这里使用 Shadowbox,我将不得不更改所有我的实现。B*tch。

我没有收到来自 Shadowbox 论坛的注册邮件,因此出于某种原因我可以在那里问这个问题,所以我想我应该在这里问。

想法?

最佳答案

替换这个:

<input type="hidden" name="memberID" value=thisID>

进入此:

<input type="hidden" name="memberID" value='+thisID+'>

您需要使用 + 符号将 thisID 的值连接到完整字符串中。

完整代码:

$(document).on("click","#mail",function(e){
    e.preventDefault();
    var thisParentClass = $(this).parent().attr("class");
    alert (thisParentClass);
    var thisIDpos = thisParentClass.indexOf("id-")+3;
    var thisID = thisParentClass.substr(thisIDpos, 3);
    alert(thisID);
     Shadowbox.open({
        content:    '<form method="post" class="mailForm" action="#"><input type="hidden" name="memberID" value='+thisID+'><p>Please be advised that the member may not be actively receiving mail.. or they might just not care at all.  They have lives too you know.</p>Your E-mail:<input type="text" name="fromEmail" size="25"> <br>Your Name: <input type="text" name="fromName" size="25"> <br>Your Message: <br><textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br><button type="submit" onclick="return false;" id="mailSubmit" value="Submit">Submit</button> ',
        player:     "html",
        height:     350,
        width:      350,
        options: {modal:true}
});

关于javascript - 将变量传递到 Shadowbox 模态窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9532674/

相关文章:

javascript - 使用 hammer.js 循环从第一个 if 跳到第二个

javascript - 一旦另一个带有 fadeIn() 的 div 出现,div 就会被推下

jquery - 克隆表格无法提交

jquery - 添加类别但更改单个元素的特定宽度

ruby-on-rails - 让 rufus-scheduler 在 Heroku 上工作

javascript - 如何在 SQL 中保存 OFFSET 的当前状态

javascript - 从具有函数作用域的变量中获取值

Javascript:将数据导出到 .txt 文件

javascript - 如何正确配置 MAIL_URL?

php - 无法使用 PHPMailer 和 Mailtrap 发送邮件