我正在尝试向网站添加电子邮件服务。我有一个模式消息窗口弹出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论坛的注册邮件,所以我可以出于某种原因问这个,所以我想我会问这里。
想法?
答案 0 :(得分:1)
您只是缺少一些引号并加上'
$(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}
});
答案 1 :(得分:1)
替换它:
<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}
});
答案 2 :(得分:0)
从您发布的代码中,您不会将ThisID值添加到代码中,而只是将其写入内容。
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> '
ThisID应该通过'+ ThisID +'添加,如下所示:
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>