如何为MVC4中的输入框设置MVC编辑器的% [英] How to set % for MVC Editorfor input box in MVC4

查看:53
本文介绍了如何为MVC4中的输入框设置MVC编辑器的%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个Editorfor字段,我想将其作为一个百分比字段。如果我将光标放在输入字段上,它将显示数字,如果我删除焦点它应该变为%(例如放置光标和类型2并删除焦点然后它应该变为2%)。我正在尝试实现自定义属性,我不知道如何实现。有人可以帮忙提供示例代码或任何其他替代方案。



提前致谢..

解决方案

你的问题有点令人困惑,一旦你说,你只想在输入处于悬停状态时获得数字,然后你说你要写'2'然后写'2%'。我不明白。



但是,你可以这样做,首先创建一个HTML元素,



 <  输入    type   =  text    value   =     id   =  toWorkOn    /  >  





现在使用jQuery处理悬停事件,



  //  悬停时, 

' #toWorkOn')。hover( function (){
// 如果元素的值发生变化


this )。change( function (){
< span class =code-comment> // 保持值
// 或在此处执行任何操作。
});
});





我希望我已经回答了!


Hi I have a Editorfor field and i want to make this a percentage field. if i put cursor on the input field it will show the number if i remove focuse it should become % (for example put cursor and type 2 and remove focus then it should become 2%). I am trying to implement custom attribute i don't know how to implement. Can somebody please help with sample code or any other alternative.

Thanks in advance..

解决方案

Your question is a little bit confusing, once you say, you want to get the number only if the input is in hover, and then you say you want to write the '2' and then get the '2%' written. I don't understand.

However, you can do it this way, first create an HTML element,

<input type="text" value="" id="toWorkOn" />



Now handle the hover event using jQuery,

// upon hover, 


('#toWorkOn').hover(function () { // if the element's value changes


(this).change(function () { // keep the value // or do whatever here. }); });



I hope I have answered!


这篇关于如何为MVC4中的输入框设置MVC编辑器的%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆