English 中文(简体)
印刷外地投入数据与Javascript
原标题:Printing field input data live with Javascript

给你一个 j印古典问题。 I m 创建由几个不同的文本投入领域组成的旁边际工具。 该工具的目的是在模板上打印。 我试图将数据输入实地交换,但我会遇到问题,把数据输入我的 j子。 这是我所铭记的:

$( myInputField ).(function(){
      $(this).onChange(){
          // write to variable X
}
});

基本上,我希望投入中我打什么打字,然后我可以放弃对我数据库的改动。

最佳回答

是否只是投入领域的关键活动是不够的?

j 质量:

$( textarea ).keyup(function() {
    $( #foo ).html($(this).val());
});​

传真:

<textarea></textarea>
<div id="foo"></div>

<jsFiddle example

问题回答
$( #myInputField ).(function(){
      $(this).onkeyup(){
          x = this.value;
      }
});

or more succinctly:

$( #myInputField ).onkeyup(){
    x = this.value;
});

You re just looking for the value that s in myInputField within that event handler? Something like this?:

$( myInputField ).(function(){
  $(this).onChange(){
      x = $(this).val();
  }
});

如果<代码><>><>>ts已经成为一个 j物体,我就不记得我的头顶。 如果是的话,那么这项工作应当奏效,或许可以略微绕过:

x = this.val();

Additionally, you can explicitly reference the field with a normal jQuery selector if this is ever overridden with a different context, or if you want to reference other fields as well, etc.:

x = $( myInputField ).val();

问题在于,在IEC,onchange activity don t work on INPUT elements. 因此,您必须使用<条码>的关键>或<条码>。 取决于你们想要做的事情。

JS way:

document.getElementById( myInputField ).onblur = function() {
    var x = this.value
}

jQuery way:

$( #myInputField ).blur(function() {
    var x = this.value
})




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签