将div输入发送到变量中?JQuery
我试着用将div输入发送到变量中?JQuery,jquery,variables,input,Jquery,Variables,Input,我试着用contenteditable制作一个可编辑的div,这样一个人就可以把东西放进去并按下按钮。这应该会将输入文本发送到变量,但我似乎无法让它工作。有人能解释一下我做错了什么吗 HTML: <div id="InPut" style="position: absolute; left: 33.44%; top: 47.22%; width: 33.1%; height: 5.6%; right: auto; bottom: auto; border: 1px solid #ccc;
contenteditable
制作一个可编辑的div,这样一个人就可以把东西放进去并按下按钮。这应该会将输入文本发送到变量,但我似乎无法让它工作。有人能解释一下我做错了什么吗
HTML:
<div id="InPut" style="position: absolute; left: 33.44%; top: 47.22%; width: 33.1%; height: 5.6%; right: auto; bottom: auto; border: 1px solid #ccc; min-height: 3%; overflow: hidden;" contenteditable>you can write in here</div>
<div id="Button" onclick="ButtonClick();" style="position: absolute; margin: 0px; left: 44.25%; top: 55.94%; width: 11.5%; height: 8.6%; right: auto; bottom: auto; -webkit-background-size: 100%; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); background-image: url(http://i.imgur.com/PnznUlg.png); background-size: 100% 100%; background-position: 0px 0px; background-repeat: no-repeat;"></div>
下面是JSFIDLE:您需要jQuery中的方法:
function ButtonClick() {
$("#InPut").hide();
$("#Button").hide();
var theInput = $("#InPut").html();
alert(theInput);
}
您需要使用.text()或.html()方法获取值:
为您使用JSFIDLE示例:我很抱歉这个简单的问题。@ravvenna只有当您知道答案时才很容易:)div的文本似乎没有更改为已键入的输入。有什么想法吗?使用JSFIDLE-div中的div文本似乎没有更改,并且仍然说如果需要,您可以在我的php文件中写入我输入div,例如Rav,它发布的文本仍然是你可以在这里写的,我通过查看源代码看到了这一点,它没有改变任何想法?修复检查第一个答案。
function ButtonClick() {
$("#InPut").hide();
$("#Button").hide();
var theInput = $("#InPut").html();
alert(theInput);
}
ButtonClick = function() {
var Name = $('#InPut').text();
console.log('Input text: ' + Name);
$("#InPut").hide();
$("#Button").hide();
}