English 中文(简体)
• 如何利用“ j”在删除钥匙时从扼杀中提取特性
原标题:How to skip a character from a string when delete key is pressed using jQuery

如何在使用<<>j Query的载体中删除某一特性时删除主要新闻或后天的主要新闻。 例如,从1234-555号指示中,如果删除钥匙,则不应删除斜线。 不应由该治疗师担任同样职务。 从根本上说,将烟雾中的切除钥匙混为一谈。 同样,如果后天钥匙被压倒,则不应删除斜线。 不应由该治疗师担任同样职务。

最佳回答

Sure, use the keydown activity.

<>strong>EDIT: 为了在文本箱中找到 cur目前的位置,你需要使用以下功能(@CMS)。 至少:

function getCaret(el) { 
  if (el.selectionStart) { 
    return el.selectionStart; 
  } else if (document.selection) { 
    el.focus(); 

    var r = document.selection.createRange(); 
    if (r == null) { 
      return 0; 
    } 

    var re = el.createTextRange(), 
        rc = re.duplicate(); 
    re.moveToBookmark(r.getBookmark()); 
    rc.setEndPoint( EndToStart , re); 

    return rc.text.length; 
  }  
  return 0; 
}

我现在回头回答:

var nobackspace = [ - ];
$(element).keydown(function(e) {
   if(e.keyCode == 8) {//backspace key was pressed
    var pos = getCaret(this);

    if(pos > 0) pos--;  //just a precaution so we don t get a negative number

    if(!jQuery.inArray($(this).val().charAt(pos), nobackspace)) return false;
   }
});

rel=“nofollow noreferer”>

jsFiddle example

问题回答

暂无回答




相关问题
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.

热门标签