單擊電子郵件表單提交按鈕時需要按qg("identify", {"email": "<email address of the user"});
。我需要從第三方解決方案中推入代碼,我只能使用html/css/javascript。在變量中獲取電子郵件然後按下事件onclick
在這裏,我插入jQuery UI的彈出形式
$.ajax({
url: '//code.jquery.com/ui/1.12.1/jquery-ui.js',
dataType: 'script',
cache: true,
success: function() {
$("#dialog").dialog();
}
});
然後我插入的jquery UI CSS在頭
$("<link/>", { rel: "stylesheet", type: "text/css", href: "//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"}).appendTo("head");
然後我推彈出到主體
$("body").append('<div id="dialog" title="BEVAKA PRODUKT"><div id="dialog-form" title="Create new user"><p class="validateTips">Här kan du skriva in din e-post och få ett mail när produkten finns i lager igen</p><form><fieldset><label for="email">E-postadress</label><input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all"><input type="submit" tabindex="-1" style="position:absolute; top:-1000px"></fieldset></form></div><button id="create-user">Bevaka</button></div>');
她,我取的電子郵件地址在VAR emailTest
var emailTest = $("#email").val();
在這裏我提醒上點擊emailTest變量
$("#create-user").click(function(){
alert(emailTest);
});
這需要在電子郵件的形式提交要推什麼
//qg("identify", {"email": "<email address of the user"});
Protoype
var email = $("#email").val();
$("#create-user").click(function(){
qg("identify", {"email": "email"});
})
電子郵件值不會粘在變量 –
嘗試在ajax成功中添加一些控制檯日誌,單擊處理程序。 javascript/jquery是基於事件的。所以,你需要在發生事件時檢查/獲取值,而不是使用變量名。 – nightgaunt
@nightgaunt https://jsfiddle.net/hLcprteh/ –