如何修复文本框中的值? [英] How to fix a value in a textbox?

查看:119
本文介绍了如何修复文本框中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



< tr> < TD> Facebook:< / td> < TD> < input style =width:300pxtype =textname =facebookvalue =http://www.facebook.com/$facebook> < / td>< / tr>

使值 http://www.facebook.com/ 固定且不可编辑?


$ b $ p

更新:

$ facebook 部分需要可编辑!

解决方案

有两种方法可以做到这一点。一种是向它添加属性 disabled =disabled,或者向它添加 readonly



两者的工作方式不同。你需要的可能是 disabled =disabled属性。


$ b

编辑



小提琴已更新。您应该包含以下jQuery代码:

$ $ $ $ $ $ $ $ $ $ $ $ $' inpt).val('http://www.facebook.com/$facebook');
$(#inpt)。on('change',function(){
var tval = $(this).val();
$(this).val('http://www.facebook.com/'+ tval.substring(24));
});
});

你也可以使用键盘事件,我自己是jQuery的初学者,因此这个基本的代码片段。 :)另外,将输入标记更新为:

 < input id =inptstyle =width:300pxtype =textname =facebookvalue =您想要的任何价值> 


I have a textbox to save the user facebook's url.

<tr>
    <td>
        Facebook:
    </td>
    <td>
        <input style="width:300px" type="text" name="facebook" value="http://www.facebook.com/$facebook">
    </td>
</tr>

How can i make the value "http://www.facebook.com/" fixed and uneditable?

UPDATE:

the $facebook part needs to be editable!!

解决方案

There are two methods to do this. One is to add the attribute disabled="disabled" to it, or add readonly to it.

Both work differently. What you need might be disabled="disabled" attribute.

EDIT

fiddle updated. You should include following jQuery code:

$(document).ready(function() {
    $("#inpt").val('http://www.facebook.com/$facebook');
    $("#inpt").on('change', function() {
        var tval = $(this).val();
        $(this).val('http://www.facebook.com/' + tval.substring(24));
    });
});

You may use keyboard events too, I am myself a beginner in jQuery, hence this basic piece of code. :) Also, update the input tag to this:

<input id="inpt" style="width:300px" type="text" name="facebook" value="Any VALUE YOU WANT">

这篇关于如何修复文本框中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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