当用户在输入类型编号上输入小数时,事件返回空值

时间:2016-01-05 18:34:47

标签: javascript html5 input

使用Firefox的

编辑,只有Chrome错误(可能还有其他人)

我尝试从简单的hive-jdbc-1.2.1-standalone.jar hadoop-common-2.7.1.jar

获取所有事件



<dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-jdbc</artifactId>
  <version>1.1.0</version>
  <classifier>standalone</classifier>
</dependency>
&#13;
<input type="number" step="any" />
&#13;
&#13;
&#13;

当我按下或更新号码时,所有附加功能都很好。但是,当我尝试设置小数点$('input[type=number]').on('input', function() { $('#value').text($(this).val()) })时,该值为<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="number" step="any"/> <br/> <strong>Value:</strong> <span id="value"></span>

我在这里使用jQuery,但问题与Vanilla JS一样。

2 个答案:

答案 0 :(得分:1)

我能得到的最接近的是:

$('input[type=number]').on('input', function() {
  $(this).select();

  var value = window.getSelection().toString();
  window.getSelection().empty();

  $('#value').text(value);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="number" step="any"/>
<br/>
<strong>Value:</strong> <span id="value"></span>

请注意,当您输入内容时,该字段会失去焦点......

答案 1 :(得分:0)

我认为这是struct Node{ struct Node *next; int c; int d; }; struct Node *head=NULL; struct Node *current=NULL; void display(){ struct Node *temp=head; while(temp!=NULL){ printf("\nData : %d", temp->c); printf("\nData : %d", temp->d); temp=temp->next; } } //Problem here struct Node* deserialize(char* data, struct Node *p){ sscanf(data,"%d %d", &p->c, &p->d ); return p; } char* serialize(const struct Node *p){ char* ser = malloc(100*sizeof(*ser)); if(!ser){ printf("\nUnable to allocate memory"); }else{ sprintf(ser, "%d %d",p->c, p->d); } return ser; } // and here void readFromFile(){ char *d =malloc(100*sizeof(*d)); FILE *fp = fopen("read.txt", "r"); struct Node *f; for(f= head; f!=NULL; f=f->next){ fscanf(fp, "%[^\n]%*c", d); // printf("\nString : %s",d); deserialize(d, f); printf("\n%d %d", f->c, f->d); } fclose(fp); } void createNode(){ struct Node *temp = NULL; temp = (struct Node* )malloc(sizeof(struct Node)); if(temp == NULL){ printf("\n\t\tMemory for the new record cannot be allocated!!!"); return; } printf("\nEnter number"); scanf("%d",&temp->c); printf("\nEnter number"); scanf("%d",&temp->d); temp->next = NULL; if(head==NULL){ head = current = temp; }else{ current->next = temp; current = temp; } printf("Record Inserted"); char* data = serialize(temp); FILE *fp = fopen("reads.txt", "a"); fprintf(fp, "%s\n",data); fclose(fp); free(data); } int main(){ int i; for(i=0; i<3; i++){ createNode(); } display(); readFromFile(); } type字段的问题,input(点)不是数字,但是数字是必要的,所以我想这是故障矩阵。

这里是fiddle,其中type是文本,它工作正常。