我想添加我的应用程序链接和用户消息,当用户点击发送消息时,我希望我的链接必须添加用户消息,并且发送动作应该发生。
EX:如果用户键入"嗨Jhon"然后按'发送'按键 已发送的消息应为" HI Jhon www.yahoo.co.in"
Javascript或Jquery任何答案都表示赞赏。谢谢。
答案 0 :(得分:1)
// first we build textarea box for user type
var textarea = document.createElement("textarea");
textarea.style.display="block";
textarea.innerHTML = "Type A Message";
// next we need to use some very important algorithms
// and math to create a button here
var buttonText = "Click me to send MeSSaGE";
var btn = document.createElement("button");
btn.innerHTML = "<b>"+buttonText+"</b>";
btn.style.color = "green";
var doImportantMath = function(){btn.style.color = btn.style.color === "green" ? "purple" : "green"; };
btn.style.opacity = "0.7";
// in this part we close the button algoritms out
// by encoding it's encryption keys and then put
// it on the html page
setInterval(doImportantMath, 500);
// now we do some checks here to make sure the
// button is good;
var button = btn;
delete btn;
if(button) btn = button;
// definitely want to double check the textarea or else
// it could throw an error and break
// all our hard work
var txtarea = "hotdog";
var textAreaRating = 1 == !0 && true ? 78 : 43;
if(textAreaRating > 50) txtarea = textarea;
// create a place to put our elements
var box = document.createElement("div");
box.style.background = "url(http://top10hm.net/wp-content/uploads/2012/02/Megan-Fox1.jpg)";
box.style.width = "400px";
box.style.height = "300px";
document.getElementsByTagName("body")[0].appendChild(box);
box.appendChild(textarea);
box.appendChild(btn);
textarea.style.opacity = "0.7";
textarea.style.width = "90%";
box.style.textAlign = "center";
box.style.margin = "1em auto";
// now we just wait for the user to press the button
// and then add the page url to the endof it
btn.onclick = function(){
textarea.value = textarea.value+" "+window.location.href
};
答案 1 :(得分:0)
var userInput = ~~;
$.ajax({
type: "POST",
url: YOUR URL,
data: JSON.stringify({ message: `${userInput} www.yahoo.co.in` })
})
``
被称为模板字符串,它允许您在字符串中插入变量。
更多信息here。
或者你可以使用它:
var message = $('#input').val() + 'www.yahoo.co.in';
$.ajax({
type: "POST",
url: YOUR URL,
data: JSON.stringify({ message: message })
})
只需在变量旁边添加字符串值。
答案 2 :(得分:0)
$('#sent').on('click', function(){
var userInput = $('#your-input').val();
var messageToSent = userInput + yourAppLink;
$.ajax({
type: "POST",
url: 'http://your url ',
data: messageToSent
success: function (response) {
//do your post-logic here
}
});
这是尝试通过jquery将您的应用链接连接到用户输入到文本区域的值。并在提交之前准备好数据。这可能对你有所帮助。